桌子布局挡板

发布于 2024-09-15 16:23:57 字数 1446 浏览 2 评论 0原文

我正在与 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙女山的月亮 2024-09-22 16:23:57

答案是使用神奇的layout_weight参数。

<?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
    android:layout_weight="1">
<Button  
    android:id="@+id/btn_one" 
    android:tag="1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:text=""/>
<Button  
    android:id="@+id/btn_two" 
    android:tag="2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:text="" 
    android:padding="0px"/>
</TableRow>
<TableRow
    android:layout_weight="1"
>
<Button  
    android:id="@+id/btn_three" 
    android:tag="3" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:text=""/>
<Button  
    android:id="@+id/btn_four" 
    android:tag="4" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:text=""/>
</TableRow>
</TableLayout>
</LinearLayout>

The answer is to use the magic layout_weight parameter.

<?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
    android:layout_weight="1">
<Button  
    android:id="@+id/btn_one" 
    android:tag="1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:text=""/>
<Button  
    android:id="@+id/btn_two" 
    android:tag="2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:text="" 
    android:padding="0px"/>
</TableRow>
<TableRow
    android:layout_weight="1"
>
<Button  
    android:id="@+id/btn_three" 
    android:tag="3" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:text=""/>
<Button  
    android:id="@+id/btn_four" 
    android:tag="4" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:text=""/>
</TableRow>
</TableLayout>
</LinearLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文