我想为我的 Android 应用程序制作自定义 TableRow。我从 LinearLayout 开始,这正是我想要显示的内容,但作为 TableLayout 中的 TableRow。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:weightSum="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:text="@string/Context" />
<TextView
android:id="@+id/ContextTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:weightSum="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:text="@string/SHUId" />
<TextView
android:id="@+id/SHUIdTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3" />
</LinearLayout>
...Others LinearLayouts with 2 TextViews...
</LinearLayout>
所以首先我尝试将这段代码放在 TableRow 元素中:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
...LinearLayout code from above...
<TableRow />
此时布局在 eclipse 编辑器中正确显示,但现在我在主 LinearLayout 上有一个 Lint 警告:“此 LinearLayout 布局或其 TableRow 父级是 没用的”
然后我会说 OK TableRow 是 LinearLayout 的子类然后我可以简单地删除主 LinearLayout 并将他的属性直接放在 TableRow 上,就像这样:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout >
<TextView />
<TextView />
<LinearLayout />
<LinearLayout >
<TextView />
<TextView />
<LinearLayout />
...etc...
<TableRow />
但现在布局不再正确显示(但没有警告)。我只看到第一行(第 2 个 TextView)。 我错过了什么?
最佳答案
TableRow
是 TableLayout
的子项吗?如果不是,你不应该使用 TableRow
- 没有 TableLayout
它只是一个水平的 LinearLayout
。
关于android - TableRow 内部的 LinearLayout 发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11790312/