【发布时间】:2015-04-17 20:09:37
【问题描述】:
我是 Android 开发新手。
我尝试过使用LinearLayout,现在终于使用TableLayout。
我需要一个带有 3 列的简单固定可滚动表,但我无法获得单个列表行来执行我需要的操作...我有 ListView 和 ListActivity 及其 Adapter 排序。
基本上我想要:
- 3 列,所有固定宽度,但调整到不同的屏幕 大小(因此是百分比?)
- 第一列有标题,应该是最大的。如果文本超出空间,则将其省略
- 第二列是价格
- 第三列是一个图标,应该在最右边
|-----------------------------------------| | This title exceeds th....| $500 | Icon | | This title fits | $1000 | Icon | | Other title | $25 | Icon | | Another long title th... | $1200 | Icon | |-----------------------------------------|
这是我最新的 xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<TextView
android:id="@+id/title"
android:layout_height="45dip"
android:layout_width="wrap_content"
android:layout_marginRight="10dip"
android:layout_weight="6"
android:ellipsize="end"
android:singleLine="true"
android:text="A long Title it is"
android:textSize="24sp" />
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="45dip"
android:layout_weight="3"
android:layout_marginRight="10dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Price"
android:textSize="24sp" />
<ImageButton
android:layout_weight="1"
android:id="@+id/cart"
android:gravity="end"
android:src="@drawable/cart"
android:layout_width="45dp"
android:layout_height="30dp" >
</ImageButton>
</TableRow>
</TableLayout>
结果有时候图标不在最右边,标题文字没有固定宽度……
我搜索了很多问题并尝试了很多东西(请参阅layout_weight),但到目前为止似乎没有奏效。谢谢。
【问题讨论】:
标签: android android-layout layout tablelayout