如何从单独的 xml 文件中扩展特定视图。可能吗?当我尝试设置此视图的 id 时,我只有一个 ResourceNotFoundException。也许我需要以某种方式设置文件名?
LayoutInflater inflater = LayoutInflater.from(this);
FrameLayout ingredients_frame = (FrameLayout)inflater.inflate(R.id.ingredients_frame, null);
R.id.ingredients_frame 位于单独的 xml 文件中。
例外:
android.content.res.Resources$NotFoundException: Resource ID #0x7f060032 type #0x12 is not valid
成分_frame_layout.xml:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ingredients_frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/expandable_second_layer_selector" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@android:color/white"
android:singleLine="true"
android:text="......................................................................................................................................................................"
android:textColor="@color/dark_orange"
android:textSize="18dip"/>
<TextView
android:id="@+id/ingredient_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@android:color/white"
android:textStyle="bold"
android:text="@string/friends_total"
android:textColor="@color/dark_orange"
android:textSize="18dip" />
<TextView
android:id="@+id/ingredient_data"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@android:color/white"
android:textStyle="bold"
android:textColor="@color/dark_orange"
android:textSize="18dip" />
</FrameLayout>