22

レイアウト リソース XML には、メインの RelativeLayout 内に 3 つの RelativeLayout があります。ビューは垂直に表示されます。これらの 3 つの RelativeLayout() は隣り合わせに設定されており、画面サイズに関係なく、画面全体を埋めるようにします。私の、レイアウトビュー:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backg"
 >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="@dimen/top_mr_image"
    android:src="@drawable/temp" />

<RelativeLayout
    android:id="@+id/r1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/imageView1"
    android:layout_marginLeft="10dp"
    android:background="@drawable/r1bg"
    android:layout_weight="1"

     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="@dimen/txt_mr_right"
        android:layout_marginRight="@dimen/txt_mr_right"
        android:layout_marginTop="39dp"
        android:text="S"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/textView1"
        android:layout_marginLeft="@dimen/txt_mr_right"
        android:layout_marginRight="@dimen/txt_mr_right"
        android:text="T"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

    <RelativeLayout
        android:id="@+id/r2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignTop="@+id/r1"
        android:layout_toRightOf="@+id/r1"
        android:layout_weight="1" >
    </RelativeLayout>

            <RelativeLayout
        android:id="@+id/r3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignTop="@+id/r2"
        android:layout_toRightOf="@+id/r2"
        android:layout_weight="1" >

    </RelativeLayout>

私は各relativeLayoutに対して設定weight=1し、この手法はボタンで機能します。relativeLayoutでも同じだと思いましたが、私の考えが間違っていたようです。layout_width=0dp何か案が?

UPD1: 欲しいものの画像を追加しました

ここに画像の説明を入力

4

4 に答える 4

25

RelativeLayout注意を払いませんandroid:layout_weight。(これは のプロパティですがLinearLayout.LayoutParams、 のプロパティではありませんRelativeLayout.LayoutParams。)

はるかに単純なビュー階層で、必要なレイアウトを取得できるはずです。RelativeLayout最後の 2 つの s が空であるため、何をしようとしているのか明確ではありません。純粋に垂直的な組織が必要な場合は、LinearLayout代わりに を使用することをお勧めしRelativeLayoutます。

EDIT編集に基づいて、3つの複合ビューの水平レイアウトが必要なようで、それぞれがクリック可能です。次のようなものがうまくいくと思います:

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

    <!-- First column -->
    <LinearLayout
        android:id="@+id/firstColumn"
        android:orientation="vertical"
        android:gravity="center_horizontal"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="..." />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="text 1"
            . . . />
    </LinearLayout>

    <!-- Second column -->
    <LinearLayout . . . >
        . . .
    </LinearLayout>
</LinearLayout>

ボタンの内容が正しくない場合は、第 2 レベルのLinearLayoutビューを置き換えてRelativeLayout、レイアウトの整理に役立てることができます。

于 2012-12-23T07:01:00.607 に答える
8

RelativeLayouts は重みをサポートしていません。ウェイトを使用する場合は、LinearLayout を親コンテナーとして使用する必要があります。

于 2012-12-23T06:59:02.260 に答える