【问题标题】:Android xml Table LayoutAndroid xml表格布局
【发布时间】:2014-06-09 03:45:30
【问题描述】:

所以我正在尝试创建一个看起来像这样的表:

shrimp: 12pc $10.99   24pc $18.99

scallops: 10pc $11.99   15pc $14.99

...等

但我的代码有问题,使第一列(例如shrimp)占用了大部分屏幕空间,计数和价格最终挤在屏幕右侧。

 <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_conent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="Shrimp:" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="12pc - $10.99" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="24pc - $18.99" />
    </TableRow>

有人可以告诉我这里有什么问题吗?我尝试使用布局宽度和高度,但我可以让它看起来像我想要的方式的唯一方法是如果我在第一列的布局宽度中输入错误。它看起来像我想要的那样,但如果我这样做,我会得到一个编译器错误。

【问题讨论】:

  • 所有 TextViews:将 android:layout_width="wrap_content" 更改为 android:layout_width="0dp" 这就是 weight 的工作方式。
  • 完美运行!非常感谢。

标签: android xml tablelayout


【解决方案1】:

这是因为 layout_weight 属性,尝试删除它,并在你的 TextViews 之间添加一些空间。

那就如你所愿。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 2011-01-12
    • 2017-04-15
    • 2014-05-13
    • 2011-05-02
    • 2016-07-18
    • 2015-06-02
    相关资源
    最近更新 更多