http://img683.imageshack.us/img683/645/weatherscreenmockupoutl.png
我问自己编写此布局的最佳方法是什么。基本上我只需要知道如何获得等宽的七列。
提前致谢!
http://img683.imageshack.us/img683/645/weatherscreenmockupoutl.png
我问自己编写此布局的最佳方法是什么。基本上我只需要知道如何获得等宽的七列。
提前致谢!
如果它是您想要的相等宽度,您可以使用具有相同权重的子元素的线性布局。查看以下 xml。
<LinearLayout
layout:orientation="horizontal"
>
<LinearLayout
android:id = "@+id/firstcolumn"
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="0dp"
>
// do the same for your rest of the six children
</LinearLayout>
TableLayout
似乎更好,因为列数不会改变。GridView
你必须添加适配器和东西。
您可以将 TableLayout 与 TableRow 很好地结合起来,并根据需要制作行和列,非常容易。
这是一个带有 4 个按钮的 2x2 网格的示例(例如放在一个 LinearLayout 中):
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button2"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button3"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button4"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
最好是使用gridview。尝试这样的事情:
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="7" />
/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="7"
android:stretchMode="columnWidth"
android:gravity="center"
/>
试试这个..