android - TableRow 内部的 LinearLayout 发出警告

标签 android android-layout

我想为我的 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)。 我错过了什么?

最佳答案

TableRowTableLayout 的子项吗?如果不是,你不应该使用 TableRow - 没有 TableLayout 它只是一个水平的 LinearLayout

关于android - TableRow 内部的 LinearLayout 发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11790312/

相关文章:

android - Systrace 中的 VerifyClass 是什么意思?

android - 防止 HttpClient 4 跟随重定向

android - Facebook Graph 错误消息的可靠性

android - 从android中的firebase数据库中检索 child

java - Libgdx 2D 如何为正交相机创建动态雾?

安卓 ADT 21.0.0。图形布局中的内存泄漏

android - 从维度(维度)传递 layout_weight 引用

android - RTL-Layout 中忽略准则(Android Constraint-Layout)

android - 房间改造 Dagger2 MVP : Error: cannot find symbol variable DaggerAppComponent

android - 如何将 SearchView 放入高度设置为 wrap_content 的 ToolBar 中而不消失?