TableRow 中 EditText 輸入文字不顯示,疑似列寬為 0。
TableLayout 默認不自動分配列寬,第二列(EditText 所在列)需聲明可伸展。
<TableLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"> <!-- 索引 1 為第二列 -->
<TableRow>
<TextView android:id="@+id/username_label" ... android:text="Username" />
<EditText android:id="@+id/entry1" android:layout_width="match_parent" ... />
</TableRow>
<TableRow>
<TextView android:id="@+id/password_label" ... android:text="Password" />
<EditText android:id="@+id/entry2" android:layout_width="match_parent" android:password="true" />
</TableRow>
</TableLayout>
stretchColumns="1" 讓第二列佔據剩餘空間,EditText 獲得足寬顯示輸入內容。stretchColumns="0,1" 或 stretchColumns="*"(所有列)。shrinkColumns 對應收縮列,防止內容過長撐破佈局。