[英]Android equal sizing on linearlayouts
好吧,我想要以下布局:
我尝试过的是使用带有权重的线性布局。 我真的不想在每个元素上添加硬编码宽度以使其正确。 事实是,我只是无法让大盒子与第1行的第二个盒子并排而已,我似乎不明白为什么。 我可以使用权重或类似方法仅通过XML来实现吗?
到目前为止我的布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="15dp"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="1" >
</TextView>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:gravity="center"
android:text="2" >
</TextView>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:gravity="center"
android:text="3" >
</TextView>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:gravity="center"
android:text="4" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="15dp"
android:orientation="horizontal"
android:weightSum="4" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="5" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_weight="3"
android:text="Box x3 incl. margins" />
</LinearLayout>
可能有可能实现LinearLayouts,但是...使用权重,嵌套的LinearLayouts非常昂贵。 今天,我已经在真正复杂的布局上进行了优化,在不更改外观的情况下,只需14s即可在高级设备上进行渲染-少于1s。
您正在寻找的可能是TableLayout。 解决方案在这里: http : //www.mkyong.com/android/android-tablelayout-example/
Try this...
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_weight="1"
android:text="button1" />
<Button
android:layout_weight="1"
android:text="button2" />
<Button
android:layout_weight="1"
android:text="button3" />
<Button
android:layout_weight="1"
android:text="button4" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button android:text="button5" />
<Button
android:layout_span="3"
android:text="button6" />
</TableRow>
</TableLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.