Android 嵌套不同的布局
我不知道如何嵌套不同的布局。 我想要一个列表布局和一个表布局并排。例如,我希望ListLayout位于左侧,而Table layout位于ListLayout的右侧Android 嵌套不同的布局,android,layout,nested,Android,Layout,Nested,我不知道如何嵌套不同的布局。 我想要一个列表布局和一个表布局并排。例如,我希望ListLayout位于左侧,而Table layout位于ListLayout的右侧 <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="t
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:focusable="true"
android:focusableInTouchMode="true" />
还有一张桌子
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
<TableRow>
<TextView
android:layout_column="1"
android:text="Open..."
android:padding="3dip" />
<TextView
android:text="Ctrl-O"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save..."
android:padding="3dip" />
<TextView
android:text="Ctrl-S"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>
您可以从ScrollView或TableLayout作为顶部父级开始。如果是TableLayout,则需要一个TableRow
<TableLayout>
<TableRow>
{Add your ListView Here}
{Add your nested TableLayout here}
</TableRow>
</TableLayout>
{在此处添加您的ListView}
{在此处添加嵌套的TableLayout}
由于没有TableColumn或TableCell,它应该将TableRow中的每个子级视为一列。您需要有一个总体布局,然后将子布局放在其中。一种方法是使顶层布局具有水平方向的线性布局。需要记住的一点是,随着您添加越来越多的布局,性能会有所下降,因此尽量减少布局的数量是一个好主意。您是否尝试过将表和列表布局放在线性布局中
还有RelativeLayout,可用于指定子布局相对于其他子布局的位置。例如:
如果使用相对布局,则在xml文件中为表和列表视图使用以下参数。
对于ListView-->android:layout\u alignParentLeft=“true”
对于TableView,-->android:layout_toRightOf=“ListView”
此外,如果这不起作用,请再添加一个
android:layout\u alignParentRight=“true”
对于tableView,我尝试将上面显示的代码放入relativelayout中,但没有任何帮助:(@Jeena,当使用relativelayout时,您必须使用“下方”、“toRightOf”、“toLeftOf”等来告诉对象自身的位置。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<!-- List view goes here -->
<!-- Table layout goes here -->
</LinearLayout>