桌子布局挡板
我正在与 Android UI 进行斗争,尝试创建一个具有两行且每行有两个按钮的表格布局。我希望每个按钮占据行中 50% 的空间。但是,无论我将layout_width和layout_height设置为多少,我总是在每行中看到两个瘦按钮。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="@+id/tablelayout" >
<TableRow>
<Button
android:id="@+id/btn_one"
android:tag="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""/>
<Button
android:id="@+id/btn_two"
android:tag="2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""
android:padding="0px"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/btn_three"
android:tag="3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""/>
<Button
android:id="@+id/btn_four"
android:tag="4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""/>
</TableRow>
</TableLayout>
</LinearLayout>
I'm wrestling with the Android UI to try to create a table layout that has two rows with two buttons in each row. I want the buttons to each take up 50% of the space in the row. However, no matter what I set the layout_width and layout_height to, I always get two skinny buttons in each row.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="@+id/tablelayout" >
<TableRow>
<Button
android:id="@+id/btn_one"
android:tag="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""/>
<Button
android:id="@+id/btn_two"
android:tag="2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""
android:padding="0px"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/btn_three"
android:tag="3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""/>
<Button
android:id="@+id/btn_four"
android:tag="4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""/>
</TableRow>
</TableLayout>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是使用神奇的layout_weight参数。
The answer is to use the magic layout_weight parameter.