android tablelayout鏁版嵁缁戝畾鎬庝箞瀹炵幇
鍦ˋndroid涓紝TableLayout鏄竴涓敤浜庢樉绀鸿〃鏍兼暟鎹殑甯冨眬瀹瑰櫒銆傛暟鎹粦瀹氬彲浠ラ€氳繃浠ヤ笅姝ラ鏉ュ疄鐜帮細
- 鍒涘缓涓€涓猅ableLayout甯冨眬鏂囦欢锛屽苟鍦ㄥ叾涓畾涔夎〃鏍肩殑琛屽拰鍒椼€備緥濡傦紝鍒涘缓涓€涓寘鍚袱鍒楃殑琛ㄦ牸甯冨眬濡備笅锛?/li>
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Column 1" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Column 2" />
</TableRow>
</TableLayout>
- 鍦↗ava浠g爜涓壘鍒癟ableLayout锛屽苟涓哄叾缁戝畾鏁版嵁銆傚彲浠ヤ娇鐢ㄤ竴涓狶ist鎴栨暟缁勬潵琛ㄧず琛ㄦ牸鐨勬暟鎹€備緥濡傦紝鍋囪鏈変竴涓悕涓篸ataList鐨凩ist锛屽叾涓寘鍚簡瑕佹樉绀虹殑鏁版嵁銆?/li>
TableLayout tableLayout = findViewById(R.id.tableLayout);
for (Data data : dataList) {
TableRow row = new TableRow(this);
TextView textView1 = new TextView(this);
textView1.setText(data.getColumn1());
TextView textView2 = new TextView(this);
textView2.setText(data.getColumn2());
row.addView(textView1);
row.addView(textView2);
tableLayout.addView(row);
}
杩欐牱灏卞彲浠ュ皢鏁版嵁缁戝畾鍒癟ableLayout涓紝姣忎釜鏁版嵁椤归兘浼氬垱寤轰竴涓柊鐨凾ableRow锛屽苟灏嗗搴旂殑鏁版嵁濉厖鍒癟extView涓紝鐒跺悗灏嗚琛屾坊鍔犲埌TableLayout涓€?/p>
闇€瑕佹敞鎰忕殑鏄紝浠ヤ笂鍙槸绠€鍗曠殑绀轰緥浠g爜锛屽疄闄呬娇鐢ㄤ腑鍙兘闇€瑕佹牴鎹暟鎹殑绫诲瀷鍜屽竷灞€鐨勫鏉傚害鏉ヨ繘琛岄€傚綋鐨勮皟鏁淬€?/p>
相关问答