我有以下 my_layout.xml 布局
<TableLayout android:id="@+id/tlTable" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="1,2" android:layout_marginTop="20dp" >
<TableRow android:id="@+id/trRow" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/tv1" style="@style/showtext_style" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Row1" android:layout_marginRight="5dp"/>
<ProgressBar android:id="@+id/p2" style="?android:attr/progressBarStyleHorizontal" android:progressDrawable="@drawable/greenprogress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="5dp" />
<TextView android:id="@+id/tv3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0" />
</TableRow >
</TableLayout>
我想动态创建 10 行,其中所有行都是第一行的克隆,除了每行的第一个 TextView (即 tv1)的文本要更改为具有行号。所以它将是 Row1, Row2, Row3.....Row10
我怎样才能做到这一点?
最佳答案
将此代码放入单独的布局中:
<TextView android:id="@+id/tv1" style="@style/showtext_style" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Row1" android:layout_marginRight="5dp"/>
<ProgressBar android:id="@+id/p2" style="?android:attr/progressBarStyleHorizontal" android:progressDrawable="@drawable/greenprogress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="5dp" />
<TextView android:id="@+id/tv3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0" />
并使用此代码通过将此布局扩展到表格行来动态创建表格行
关于android - 在表布局中克隆行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566746/