2

これはおそらく単純なレイアウトの質問ですが、私は欲しいものを手に入れることができています。

線形レイアウト(水平)が1つあり、内部に2つのレイアウト、左側に1つ、右側に1つ(オーバーレイ、ボタンなどがあります)を表示したいと思います。スペースが許せば、右は常に完全に表示し、左は右が完全に表示された後にのみ表示するようにします。

アップデート

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

    <RelativeLayout
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:singleLine="true" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000111" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerVertical="true" />
    </RelativeLayout>
</LinearLayout>

このコードでは、左側のみが表示されます。最初のRelativeLayoutの重みを1に変更すると、両方とも画面の50%を占めることになります。これは、私が期待していることです。

私が欲しいのは、必要に応じて100%取る権利であり、100%未満の場合は、残っているものはすべて左のものに使用されます。どうすればこれを行うことができますか?

どうもありがとう!

4

1 に答える 1

2

右側からウェイトを削除し、左側の幅を0に、ウェイトを1に設定します。

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

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <!-- ..... -->

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <!-- ...... -->

    </RelativeLayout>
</LinearLayout>
于 2012-12-06T23:13:23.740 に答える