Android Studio:模式中的 TableRow 不起作用



Android 通过TableLayout作为表和TableRow作为行在 xml 文件中提供表实现,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/table_layout_4_open"
android:padding="3dip" />
<TextView
android:text="@string/table_layout_4_open_shortcut"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:text="@string/table_layout_4_save"
android:padding="3dip" />
<TextView
android:text="@string/table_layout_4_save_shortcut"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>

但是,当从 Android Studio 中的模式中拖动TableRow时,将显示以下文本:

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />

这种形式的TableRow似乎毫无用处,因为没有地方插入行视图。是安卓工作室的bug,还是我不明白如何使用这种形式的TableRow

提前感谢您的任何想法。

根据此链接 https://developer.android.com/reference/android/widget/TableRow

TableRow 应始终用作 TableLayout 的子级。如果 TableRow 的父级不是 TableLayout,TableRow 的行为将作为一个 水平线性布局。

所以你应该只在表格布局中使用它

EDIT1打开布局后,您可以在设计和文本视图之间切换,对吗?在"设计"视图中,将"文本视图"从"组件面板"拖放到 TableRow 上时,它会在"文本"视图中生成以下 xml

<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>

最新更新