开发者

TextView is truncated when placed in a TableLayout

I have a ListView dynamically populated with TextViews:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
        <ListView
                android:id="@android:id/list"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/transport_selection"
                />
</LinearLayout>

But I want to add buttons on top of the Activity, so I first moved my ListView in a TableLayout:

<?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 android:id="@+id/tableRow2" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <ListView
                android:id="@android:id/list"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/transport_selection"
                />
   </TableRow>
</TableLayout>

But then, the t开发者_高级运维ext in the TextViews is truncated: it goes over the right side of the screen.

I tryed different values for the android:layout_width attributes, but nothing is changed.

Any idea?

Regards,


You could instead use addHeaderView() or addFooterView() respectively to add a LinearLayout with horizontal orientation to your ListView, that contains a few buttons and completely eliminate the TableLayout solution. I've used this method before and it works well.

You could also float the buttons with a RelativeLayout and use addHeaderView/addFooterView to insert a spacer so they don't overlap the ListView.

Maybe there are other ways too, I would be interested to hear them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜