【问题标题】:android: tablerow mixed with columns and multiline textandroid:tablerow 与列和多行文本混合
【发布时间】:2011-02-15 03:16:21
【问题描述】:

我试图让一个表格布局包含几个表格行。其中一行包含 4 个按钮,而第二行包含很长的文本。但是,按钮的宽度会随着第二行中的文本而延伸。有没有办法防止这种情况发生?

http://img684.imageshack.us/i/tableview1.jpg/

http://img521.imageshack.us/i/tableview2.jpg/

这是我的xml文件:(这个网站对xml文件不友好)

AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>

TableLayout
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_x="0px"
android:layout_y="10px"
>

TableRow
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

Button
android:id="@+id/widget30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
>
</Button>

Button
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
>
</Button>

Button
android:id="@+id/widget32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
>
</Button>

Button
android:id="@+id/widget33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
>
</Button>
</TableRow>

TableRow
android:id="@+id/widget35"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

TextView
android:id="@+id/widget40"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextViewTextViewTextViewTextViewTextViewTextView"
>
</TextView>
</TableRow>

</TableLayout>
</AbsoluteLayout>

【问题讨论】:

  • 也尝试在代码中设置属性,没用。是安卓的bug吗?

标签: android view tablelayout tablerow


【解决方案1】:

尝试对 TextView 使用 android:layout_span="4"

将 4 替换为第一行中的列数(按钮)是什么......

另外,您可以从 Tablerow 中省略 android:layout_width 和 layout_height 参数

【讨论】:

  • 没有成功。屏幕外的文字被拉长了,第一个按钮还是那么大。我开始怀疑这是否是android的错误?
  • 它对我有用,这是我身边第二行的工作 XML(可能你将 layout_span 属性放在错误的位置): 此外,您可以轻松地从 Button 和其他 tablerow 标记中省略:layout_width="wrap_content" layout_height="wrap_content"。
  • 另外,为什么要使用 AbsoluteLayout,除非绝对必要,否则我不建议使用它。
  • 谢谢...虽然它仍然不适合我。我已经放弃并为这些按钮使用了单独的线性布局。
猜你喜欢
  • 2012-01-30
  • 1970-01-01
  • 1970-01-01
  • 2012-05-04
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-19
相关资源
最近更新 更多