首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

Android 代碼動態設置 TableRow 子視圖列索引

     編輯:程式設計綜合問答

XML 中的寫法

<TextView android:layout_column="3" />

Java 代碼實現

使用 TableRow.LayoutParams 構造函數傳入列索引:

TextView tv = new TextView(this);
TableRow.LayoutParams params = new TableRow.LayoutParams(3); // 參數即 column 索引
tv.setLayoutParams(params);
tableRow.addView(tv);

補充說明

  • TableRow.LayoutParams(int column) 構造函數對應 layout_column。
  • 若需跨列,使用 new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f) 並配合 params.span = 2(API 14+)。
  • 動態添加視圖後請調用 requestLayout() 刷新佈局。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved