5

ネストのレイアウトの問題に直面し、いくつかの例外をスローします。エラーは「このLinearLayoutレイアウトまたはそのLinearLayout親は役に立たない...」です。私はこの設定によってこの警告を無視できることを知っています。

設定:ビルドパス->ビルドパスの構成.... Android Lintの設定でUselessParentを探し、無視する重大度を設定するか、[すべて無視]をクリックします。

ただし、Eclipseのグラフィカルレイアウトでは何も表示できず、エラーメッセージが表示されます-「インデックス:0、サイズ0、例外の詳細はウィンドウ>ビューの表示>エラーログに記録されます」。

グラフィックレイアウトにネストレイアウトを表示するにはどうすればよいですか?

これが私のコードです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/menu_bg2"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item1"
            android:src="@drawable/alarm2x" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item2"
            android:src="@drawable/bank2x" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item3"
            android:src="@drawable/brief_case2x" />

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item4"
            android:src="@drawable/trolley2x" />

        <ImageButton
            android:id="@+id/imageButton5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item5"
            android:src="@drawable/calculator2x" />

    </LinearLayout>
</LinearLayout>

皆さんありがとう。

4

6 に答える 6

3

最初のLinearLayoutには、ビューが1つしかないため、LinearLayoutです。

図解された構造は次のとおりです。

LinearLayout
    LinearLayout
        ImageButton
        ImageButton
        ImageButton
        ImageButton
        ImageButton
    // You should add another View or ViewGroup for the first LinearLayout

LinearLayoutはViewGroupのサブクラスであり、少なくとも2つ(CMIIW)のいくつかのビューをグループ化することを目的としています。

したがって、警告が発行されたのは、最初のLinearLayoutにグループ化するものがないか、省略しても問題がないと想定されたためです。

英語での説明が悪いとすみません。

于 2013-04-08T17:26:51.970 に答える
2

あなたは2つ持っていますLinearLayout、そのうちの1つは今まで役に立たないです。この警告は、それらの1つを削除することを提案します。このような:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/LinearLayout1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/menu_bg2"
          android:orientation="vertical" >

     <!-- your other ImageView etc.-->
</LinearLayout>
于 2012-07-18T08:56:13.223 に答える
2

これを親のLinearLayoutに追加するだけです。

tools:ignore="UselessParent"

デフォルトでは、Android Studioは、これらの警告が役に立たない場合に表示します。tools:ignore="UselessParent"この警告が表示されないようにします。

于 2018-10-26T12:26:19.060 に答える
0

あなたは試すことができます

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/menu_bg2"
    android:orientation="vertical" >

ただし、Eclipseのグラフィックレイアウトを信頼することはありません。

編集 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
于 2012-07-18T08:50:27.837 に答える
0

2つのlinearlayoutを開きましたが、閉じるのは1つのlinearlayoutだけです。

ただし、2番目の線形レイアウトは、ボックスをボックス内に配置してから2番目のボックスにアイテムを挿入するため、意味がありません。

于 2012-07-18T08:58:55.637 に答える
0

おそらくあなたを助けます:

android:layout_alignWithParentIfMissing ="true"
于 2014-09-23T11:03:07.717 に答える