yra*_*abi 3 android view android-layout android-xml
在我的项目中,我需要为视图设置始终常量ID.我的意思是不同应用程序版本之间的ID是不变的.经过一些调查后,我发现它可以通过使用来实现,values/public.xml
并且该文件中声明的任何id在将来的构建中都不会改变.现在的问题是我无法在某些布局文件中定义视图的id.这是我的layout.xml,其中包含一个带有Id的ImageView,应该将其添加到public.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_item_selector" >
<ImageView
android:id="@+id/index_row_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="@dimen/padding_small" />
<ImageView
android:id="@+id/index_row_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/index_row_search" />
<TextView
android:id="@+id/index_row_caption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/index_row_icon"
android:layout_toRightOf="@id/index_row_search"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge" />
Run Code Online (Sandbox Code Playgroud)
这是public.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<public type="string" name="no_internet" id="0xAA0a0001" />
<public type="id" name="index_row_search" id="0xAA0b0015" />
</resources>
Run Code Online (Sandbox Code Playgroud)
eclipse在我添加id"index_row_search"的行上显示错误,并说:
error: Public symbol id/index_row_search declared here is not defined!
但正如您在上面的布局文件中看到的,我有一个带有该ID的ImageView.它想知道上面一行的字符串id定义没有错误!
那么,我应该如何在public.xml中定义View的Id?
在值中创建一个新的xml ids.xml,其中所有id值都是常量.
<resources>
<item type="id" name="index_row_search" />
</resources>
Run Code Online (Sandbox Code Playgroud)
我认为如果你将资源id从R.java复制到public.xml会更好,第一次避免像入口索引这样的错误比可用符号大,并且还要保持资源类型一致.
归档时间: |
|
查看次数: |
12874 次 |
最近记录: |