3

私はこれに似たものを作ろうとしています-Androidレイアウト(ユーザーインターフェイス)のみ最初の列を4の重みで、2番目の列を2の重みで(また2行で)、最後の列を重みで作成したい1の(および3行でも)...問題はそれ自体がめちゃくちゃです(答えをコピーして貼り付け、必要に応じてすべてを変更しましたが、めちゃくちゃになり続けます.. =)何か助けはありますか?[コード]

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_color"
    android:orientation="vertical"

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:gravity="center_horizontal|center_vertical"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textDishes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="@string/dishes"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/imageDishes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="@dimen/seperator_size"
        android:background="@color/seperator" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:measureWithLargestChild="true"
        android:orientation="horizontal"
        android:weightSum="2" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textfood"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/food"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageView
                android:id="@+id/imagefood"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_height="@dimen/seperator_size"
            android:background="@color/seperator" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textMalls"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/malls"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageView
                android:id="@+id/imageMalls"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="@dimen/seperator_size"
        android:background="@color/seperator" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:weightSum="3"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_height="@dimen/seperator_size"
            android:background="@color/seperator" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/coupons"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>

         <View
            android:layout_width="fill_parent"
            android:layout_height="@dimen/seperator_size"
            android:background="@color/seperator" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/markets"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>
[/code]

それが結果です -

ここに画像の説明を入力

結果は次のようになります ここに画像の説明を入力

4

3 に答える 3

3

作業例を今すぐ編集

垂直方向の仕切りがまだ機能していないため、これは完全な答えではありませんが、うまくいけば、正しい方向に進むことができます。

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="4"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textDishes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Dishes"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ImageView
        android:id="@+id/imageDishes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:background="@color/red" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textfood"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Food"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/imagefood"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <View
        android:layout_width="5dp"
        android:layout_height="fill_parent"
        android:background="@color/red"
        android:gravity="center" >
    </View>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textMalls"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Malls"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/imageMalls"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
</LinearLayout>

<View
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:background="@color/red" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="App name"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <View
        android:layout_width="5dp"
        android:layout_height="fill_parent"
        android:background="@color/red"
        android:gravity="center" >
    </View>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Coupons"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <View
        android:layout_width="5dp"
        android:layout_height="fill_parent"
        android:background="@color/red"
        android:gravity="center" >
    </View>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Markets"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
</LinearLayout>

ここに画像の説明を入力

于 2013-07-16T18:34:11.840 に答える
2

XML をここに含めたとき、これが単に間違いだったのかどうかはわかりませんが、親 LinearLayout の後に ">" がありません。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background_color"
android:orientation="vertical"

する必要があります

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background_color"
android:orientation="vertical" >

さらに、この親レイアウトの子の一部で重みを使用していますが、親 LinearLayout で weightSum 合計を指定していません。weightSum は、子の間で分配される合計の重みであるため、それらの重みを合計すると、この weightSum になる必要があることに注意してください。また、念のために言っておきますが、ネストされたウェイトを使用すると (それを追加した場合に実行することになります)、パフォーマンスが低下します。

あなたの問題に対する最善の解決策は、LinearLayout を使用する代わりに、別のレイアウト オプションを検討することでしょうか? ただし、この方法で機能させることはできます。親の weightSum 7 を作成し、これを必要に応じて子に配布するようにしてください。

あなたの写真(および線形レイアウトを使用)によると、次のようになります。

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="7" >

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weight="4" >

// This one's child here - it has weight 1.

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="2"
    android:weight="2" >

// This one's children here - they both have weight 1.

 <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="3"
    android:weight="1" >

// This one's children here - they all have weight 1.

LinearLayouts も閉じることを忘れないでください。そのコードもテストしていないので、エラーがないか確認してください。

于 2013-07-16T17:19:34.263 に答える