我有一个动态布局,并在线性布局中添加组件。组件的数量也是动态的。我可以拥有布局的多布局方向吗?
当线性布局方向为水平时,水平添加项目,垂直添加垂直项目时。
现在,我可以首先水平垂直放置物品,然后垂直垂直放置物品。
或者我可以使用任何其他布局来满足我的需求。
像这样
我有一个动态布局,并在线性布局中添加组件。组件的数量也是动态的。我可以拥有布局的多布局方向吗?
当线性布局方向为水平时,水平添加项目,垂直添加垂直项目时。
现在,我可以首先水平垂直放置物品,然后垂直垂直放置物品。
或者我可以使用任何其他布局来满足我的需求。
像这样
你绝对可以有嵌套LinearLayout
元素与多个方向。例如:
<LinearLayout
android:id="@+id/main_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/firstRow"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal" >
...
</LinearLayout>
<LinearLayout
android:id="@+id/secondRow"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal" >
...
</LinearLayout>
<LinearLayout
android:id="@+id/thirdRow"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal" >
...
</LinearLayout>
</LinearLayout>
使用这样的结构将允许您构建所描述的布局。
因为你可以做以下动态行:
layout_row.xml
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal" />
MainActivity.java
mainLayout = (LinearLayout) findViewById(R.id.main_layout);
// for each dynamic row you can inflate a new view and add it
dynamicRow1 = getLayoutInflater.inflate(R.layout.layout_row, null);
mainLayout.addView(dynamicRow1);
dynamicRow2 = getLayoutInflater.inflate(R.layout.layout_row, null);
mainLayout.addView(dynamicRow2);
dynamicRow3 = getLayoutInflater.inflate(R.layout.layout_row, null);
mainLayout.addView(dynamicRow3);
在每一行中,你可以以编程方式添加动态您需要使用相同类型的逻辑创建视图。
嗨!你可以使用布局土地为新的XML文件...你可以阅读有关Android如何在这里提供这个http://developer.android.com/guide/topics/resources/providing-resources.html – Aamirkhan
你可以使用layout-土地为新的xml文件...你可以阅读关于android如何在这里提供这个http://developer.android.com/guide/topics/resources/providing-resources.html – Aamirkhan