线性布局有两个按钮并排 - 安卓
我有3个按钮下出现低于对方的,其中layout.xml ...线性布局有两个按钮并排 - 安卓
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/btn_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Car" />
<Button
android:id="@+id/btn_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Vehicle" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btn_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bike" />
</LinearLayout>
</LinearLayout>
我想通过有前两个按钮侧方(btn_1和btn_2)。任何人都可以给我一个关于如何做到这一点的暗示?
非常感谢
只是改变android:orientation="vertical"
到布局的android:orientation="horizontal"
和每一件事情都会正常工作
变化的线性布局方向垂直成Horizontal.And然后给体重为你的两个按钮为1或2 。按照你的愿望,按钮将被平等地安排。
最好的办法就是进行布局,然后把你的按钮,像这样的代码
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/Button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/Home1"/>
<Button
android:id="@+id/Button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/NextL"/>
在这种形状必须在同一行那么容易两粒扣:d
似乎像你forgor一个结束标签?此外,根据[docs](http://developer.android.com/reference/android/widget/TableRow.html),“TableRow应始终用作TableLayout的子项”。 – dst 2014-02-17 20:48:23
是的,我忘记了这些,并且它不是一个义务,他们可以在大多数布局中使用,我在LinearLayout中使用它们,并且这会产生 – user3287335 2014-02-22 20:57:59
这就是为什么文档只提及* should *而不是* must *。但是,正如文件建议反对它,我不会推荐它,以防万一新的Android版本在那里出现问题。 – dst 2014-02-23 14:08:43
被相同的情况:http://stackoverflow.com/questions/5551349/2-buttons-side-by-side-android-layouts/21411490#21411490 – iarroyo 2014-01-28 16:48:52