我刚刚发现了layout_column和layout_span。
目前,我使用的是layout_weight,或普通的旧layout_width="dp"。
有人能解释一下最有效的/流行的/有用的语法吗?我觉得我总是会发现新的语法,并且想重写我的布局代码。
发布于 2013-09-27 18:07:00
layout_column和layout_span都是表布局的属性。您只能在表布局中使用它们
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:id="@+id/info"
android:layout_span="2"
android:text="some text"
android:padding="3dip"
android:layout_gravity="center_horizontal" />
<EditText android:id="@+id/info"
android:layout_span="3"
android:text="some text"
android:padding="3dip"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow>
<TextView android:text="some other text"
android:padding="3dip"
android:layout_span="1" />
<TextView android:text="more text"
android:padding="3dip"
android:layout_span="4"/>
</TableRow>
</TableLayout>在上面的xml中,两行占用的空间相同,唯一的区别是,在第一行中,Textview和EditText的比率为2:3,而在第二行,TextViews的占用空间为1:4。
布局着色简单地表示列的索引,其中这个子列应该是.Also,需要记住的一点是,列从索引0开始。
目前最好的布局是相对布局,这是我推荐的,因为它节省了很多代码行,也避免了布局嵌套,也避免了不必要的布局嵌套。重量概念是傻瓜概念,以作出复杂的布局,如果使用的权重明智,你已经把你的风险因素到0%。
发布于 2013-09-27 17:56:46
布局属性背后没有大的想法,更多的是一件实际的事情。我会研究尽可能多的现有屏幕,这样我就知道人们是如何做到这一点的。我将从SDK示例开始。
https://stackoverflow.com/questions/19057074
复制相似问题