Android 布局充气器-仅适用于另一布局中的部分布局
在我的应用程序中,我有一个布局列表_item.xml,其中有3个文本视图,它们是从一个数组填充的,我想在另一个布局中单独膨胀这3个文本视图。我想要膨胀的布局是一个单独的xml文件layout_result.xml,它有一个按钮和android搜索小部件 list_item.xml的布局文件Android 布局充气器-仅适用于另一布局中的部分布局,android,android-layout,Android,Android Layout,在我的应用程序中,我有一个布局列表_item.xml,其中有3个文本视图,它们是从一个数组填充的,我想在另一个布局中单独膨胀这3个文本视图。我想要膨胀的布局是一个单独的xml文件layout_result.xml,它有一个按钮和android搜索小部件 list_item.xml的布局文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#F0F8FF"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="@+id/ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/ProductName"
android:layout_alignBottom="@+id/ProductName"
android:layout_alignParentLeft="true"
android:text="New Text" />
<TextView
android:id="@+id/Status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="17dp"
android:layout_marginTop="42dp"
android:text="New Text" />
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/Status"
android:layout_alignBottom="@+id/Status"
android:layout_centerHorizontal="true"
android:text="New Text" />
</RelativeLayout>
您应该能够只创建一个布局XML。不确定您以前是怎么做的,但您可以这样做:
<RelativeLayout>
<RelativeLayout>
<TextView/>
<TextView/>
<TextView/>
</RelativeLayout/>
<SearchView/>
<Button/>
</RelativeView>
ViewGroup container = (ViewGroup) findViewById(R.id.FrameLayoutId);
container.addChild(yourInflaterItemsView);
希望这有帮助include不会膨胀。顺便说一句,我读了三遍,我不明白这个问题。你能重新措辞一下吗?你好,布莱克贝尔,我现在已经重新措辞了我的问题。希望它是清楚的!我也读了好几遍,完全弄糊涂了。但是,您可能想要做的是将list_resut.xml作为活动的setContentView中的布局,并向其中添加ListView。然后像现在一样在getView中放大TextViews布局。您好,codeMagic,是的,我之前尝试过这个,但我总是收到一个错误,说找不到id的视图。所以,我问是否有其他方法可以这样做。
<RelativeLayout>
<RelativeLayout>
<TextView/>
<TextView/>
<TextView/>
</RelativeLayout/>
<SearchView/>
<Button/>
</RelativeView>
<RelativeLayout>
<FrameLayout/>
<SearchView/>
<Button/>
</RelativeLayout>
<RelativeLayout>
<TextView/>
<TextView/>
<TextView/>
</RelativeView/>
ViewGroup container = (ViewGroup) findViewById(R.id.FrameLayoutId);
container.addChild(yourInflaterItemsView);