Alexis
Alexis

Reputation: 16829

LinearLayout inside TableRow makes a warning

I want to make a custom TableRow for my android application. I started from the LinearLayout which is exactly what I want to display but as a TableRow in a TableLayout.

<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>

So first I tried to put this code inside a TableRow element :

<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 />

At this point the layout is displayed properly in the eclipse editor BUT now I have a Lint warning on the main LinearLayout : "This LinearLayout layout or its TableRow parent is useless"

Then I'd say OK TableRow is a subclass of LinearLayout then I could simply remove the main LinearLayout and put his properties directly on the TableRow just like this :

<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 /> 

But now the layout is not correctly displayed anymore (but no warning). I see only the first line (with the 2 first TextView). What am I missing?

Upvotes: 2

Views: 2792

Answers (1)

devmiles.com
devmiles.com

Reputation: 10014

Is your TableRow a child of TableLayout? If not you shouldn't be using TableRow - without TableLayout it's just a horizontal LinearLayout.

Upvotes: 1

Related Questions