0

私はこのレイアウトを持っています:

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

    <RadioGroup
        android:id="@+id/MyTabs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton ... />

        <RadioButton ... />
    </RadioGroup>

    <SquareImageView
        android:layout_height="match_parent" />

</LinearLayout>

SquareImageView のコードは次のとおりです。

public class SquareImageView extends ImageView {
   public SquareImageView(Context context) {
     super(context);
   }

   public SquareImageView(Context context, AttributeSet attrs) {
     super(context, attrs);
   }

   public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
     super(context, attrs, defStyle);
   }

   public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     int size = getMeasuredHeight();//Math.min(getMeasuredWidth(), getMeasuredHeight());
     setMeasuredDimension(size, size);
   }
}

今、私が達成したいのはこれです:

ここに画像の説明を入力

RadioGroup ができるだけ多くのスペースを占めるようにしたいと考えています。LinearLayout の高さは、RadioGroup の必要な高さに適応する必要があります。各 RadioButton は、RadioGroup の 50% を占める必要があります。SquareImageView は、その高さを LinearLayout の高さに合わせて調整する必要があり、幅も正方形にするために調整する必要があります。

これは可能ですか?

RadioGroup 自体は問題ありませんが、幅を自動的に調整できないため、難しいのは正方形の ImageView です。正方形ですが、手動で幅を設定する必要があります。幅を手動で設定しないと (Eclipse プレビュー レイアウト マネージャーでは) 正方形に見えますが、最終的には画面の外側になり、RadioGroup が画面幅全体を占有します。幅を広くしすぎると、右側にデッドスペースができてしまいます。

あらゆる種類の設定をいじってみましたが、何もうまくいきません。寸法を絶対値で設定することは避け、RadioGroup の高さによって残りのビューの寸法を決定したいと思います...

4

2 に答える 2

0

これを試して:

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

    <RadioGroup
        android:id="@+id/MyTabs"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weig="1" >

        <RadioButton 
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" 
            ... />

        <RadioButton 
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" 
            ... />
    </RadioGroup>

    <SquareImageView
        android:layout_width="0dp"
        android:layout_height="match_parent" />

</LinearLayout>
于 2013-06-28T15:46:32.830 に答える
0

以下の手順を試すことができます。 1、以下のようにレイアウトを設定します。

<RadioGroup
    android:id="@+id/MyTabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="1" >

    <RadioButton 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.5" 
        ... />

    <RadioButton 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.5" 
        ... />
</RadioGroup>

<SquareImageView
    android:layout_width="0dp"
    android:layout_height="match_parent" />

2、ビューが読み込まれたら、プログラムで線形レイアウトの高さを見つけ、プログラムで正方形ビューの幅をこの同じ値に設定して正方形にします

3、画面の幅を見つけて、残りの画面幅を占めるように、ラジオグループの幅を画面幅と上記のスクエアビュー幅の差に設定します。

于 2013-06-28T16:31:23.963 に答える