Android TableLayout:以编程方式拉伸列

问题描述 投票:-1回答:2

我正在创建TableLayout

TableLayout的xml代码:

<TableLayout
        android:id="@+id/productList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
</TableLayout>

我想动态添加n行,但每行只想2列喜欢这张图片

我在布局文件中使用了android:strechColumns,但没有成功。

我如何动态解决此问题。?

请帮助...

提前感谢。

我正在创建TableLayout,TableLayout的xml代码: ...

android android-tablelayout
2个回答
4
投票
<?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" android:orientation="vertical" android:padding="10dp" > <ScrollView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TableLayout android:id="@+id/tableLayoutProduct" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@android:color/white" android:stretchColumns="*" > </TableLayout> </LinearLayout> </HorizontalScrollView> </ScrollView> </LinearLayout>

1
投票
© www.soinside.com 2019 - 2024. All rights reserved.