android tablelayout 固定列 - 没有得到想要的结果
android tablelayout fixed columns - not getting desired results
我是 Android 开发新手。
我试过 LinearLayout
,现在终于 TableLayout
。
我需要一个具有 3 列的简单固定可滚动 table,但我无法让单个列表行执行我需要的操作...我有 ListView
和 ListActivity
及其 Adapter
排序。
基本上我想要:
- 3 列固定宽度,但适应不同的屏幕
大小(因此百分比?)
- 第一列有标题,应该是最大的。如果文本超过 space,请将其省略
- 第二栏是价格
- 第三列是一个图标,应该在最右边
|-----------------------------------------|
| This title exceeds th....| 0 | Icon |
| This title fits | 00 | Icon |
| Other title | | Icon |
| Another long title th... | 00 | 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
),但到目前为止似乎没有效果。谢谢。
在table行(或线性布局的水平方向)处理android:layout_weight
时建议使用android:layout_width="0dp"
能否尝试将 layout_width 属性设置为 0dp。我认为它会起作用。
我是 Android 开发新手。
我试过 LinearLayout
,现在终于 TableLayout
。
我需要一个具有 3 列的简单固定可滚动 table,但我无法让单个列表行执行我需要的操作...我有 ListView
和 ListActivity
及其 Adapter
排序。
基本上我想要:
- 3 列固定宽度,但适应不同的屏幕 大小(因此百分比?)
- 第一列有标题,应该是最大的。如果文本超过 space,请将其省略
- 第二栏是价格
- 第三列是一个图标,应该在最右边
|-----------------------------------------| | This title exceeds th....| 0 | Icon | | This title fits | 00 | Icon | | Other title | | Icon | | Another long title th... | 00 | 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
),但到目前为止似乎没有效果。谢谢。
在table行(或线性布局的水平方向)处理android:layout_weight
android:layout_width="0dp"
能否尝试将 layout_width 属性设置为 0dp。我认为它会起作用。