2010-12-29 8 views
17

私は主なアクティビティとしてTableRowと共にTableLayoutを使用しています。水平方向のラジオグループ内のレイアウトを管理する

Inside TableLayoutは、アクティビティ内の2つのラジオボタンを含むラジオグループです(ラジオグループはテーブル行内にあります)。一番右のラジオボタンを右端の画面に合わせることができるように、「ラジオボタン」と「右ボタン」の間に「ギャップ」があります(右のラジオボタンの後ではなく)。すなわち

したがって、代わりに
| (x)(x)ギャップ|
私は持っています
|(x)gap(x)|

ここで(x)はラジオボタンで、画面の端である

両方のボタンを中間に置くことができます(つまり、| gap(x)(x)gap |)。しかし、私はそれらを分割できないようです私が前に言ったようにしたい方法

答えて

0

これまでの解決方法はありますか?私の中間的な解決策は助けになるかもしれませんが、それは私のための完全な絵ではありません。私は特定の幅を設定することで、これを行うことができましたが、これはビューが画面の幅に合わせてサイズを変更することはできません:

<RelativeLayout 
    android:id="@+id/overall_layout" 
    android:layout_width="290dp" android:layout_height="wrap_content"> 

    <RadioGroup android:id="@+id/overall" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <RadioButton android:id="@+id/overall_1" android:tag="1" 
      android:button="@drawable/radio_1" 
      android:layout_width="50dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="wrap_content"></RadioButton> 
     <RadioButton android:id="@+id/overall_2" android:tag="2" 
      android:button="@drawable/radio_2" 
      android:layout_width="50dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="wrap_content"></RadioButton> 
     <RadioButton android:id="@+id/overall_3" android:tag="3" 
      android:button="@drawable/radio_3" 
      android:layout_width="50dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="wrap_content"></RadioButton> 
     <RadioButton android:id="@+id/overall_4" android:tag="4" 
      android:button="@drawable/radio_4" 
      android:layout_width="50dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="wrap_content"></RadioButton> 
     <RadioButton android:id="@+id/overall_5" android:tag="5" 
      android:button="@drawable/radio_5" 
      android:layout_width="50dp" 
      android:layout_height="wrap_content"></RadioButton> 
    </RadioGroup> 
    <TextView android:text="left" android:id="@+id/left" 
     android:layout_below="@id/overall" 
     android:layout_alignParentLeft="true" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
    <TextView android:text="right" android:id="@+id/right" 
     android:layout_below="@id/overall" 
     android:layout_alignParentRight="true" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
    </RelativeLayout> 

注最後のボタン上の余裕がありません。

ラジオグループに5つのカスタムボタンがあるようにしようとしています.1つめの左揃えと最後の右揃えです。ボタンの幅はちょうど50ピクセルで、ボタンに関連付けられたテキストは個別に表示されません。下の2つのテキストは、相対的なレイアウトで左右に並んでいます。 "layout_gravity"を使用すると効果がなく、layout_weightは各ボタンの右側にパディングを追加するため、一番右のボタンはもはや正当化されなくなります。

多くの髪を引っ張っています。

9

私の解決策が見つかりました。重力と重力の組み合わせとマージンの除去。ラジオグループはlayout_width = "fill_parent"を持つことができます。各ラジオボタンはlayout_weight = "1"でなければなりませんが、デフォルトのラジオボタンの画像幅である "37"のデフォルト値を上書きするには、各ラジオボタンのlayout_widthを指定する必要があります。

 <RadioGroup android:id="@+id/overall" 
     android:layout_width="fill_parent" android:layout_height="80dp" 
     android:gravity="center" 
     android:orientation="horizontal"> 

まずボタンを持っている必要があります。

   android:layout_weight="1" 
      android:layout_gravity="center|left" 

を最終ボタンが持っている必要があります。

  android:layout_gravity="center|right" 

注:すべてのボタンがlayout_graviotyセットが、一番右のボタンの無いlayout_weight設定があります!

+0

私はこれを試してみました、私はそれを使用するが、それは私のコードのために仕事をdoesntの、最初のボタンは、行全体 – elfekz

32

あなたは画面を左右方向に均等にスペースにボタンの任意の数を必要とするすべて:

  1. RADIOGROUPが android:orientation="horizontal" & android:layout_width="fill_parent"
  2. を持つように各ラジオボタンが 除き、 android:layout_weight="1"を持っている必要がありました右端のボタン( の画面の右端にそれを一致させるには)

Landscape screenshot

これは把握する私に時間を要しました。

ここでは、アンケートアプリの2つのテキストラベルと画面の右端と左端のボーナスを使用したコード例を示します。

<RadioGroup 
    android:id="@+id/radio_group" 
    android:orientation="horizontal" 
    android:layout_below="@id/question" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="gone" 
> 
    <RadioButton 
     android:id="@+id/strong_disagree_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="1" 
    /> 
    <RadioButton 
     android:id="@+id/disagree_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/disagree" 
    /> 
    <RadioButton 
     android:id="@+id/neutral_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/neutral" 
    /> 
    <RadioButton 
     android:id="@+id/agree_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/agree" 
    /> 
    <RadioButton 
     android:id="@+id/strong_agree_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="5" 
    /> 
</RadioGroup> 
<TextView 
    android:id="@+id/disagree_label" 
    android:text="@string/strongly_disagree_txt" 
    android:layout_below="@id/radio_group" 
    style="@style/TextAppearance" 
    android:visibility="gone" 
    /> 
<TextView 
    android:id="@+id/agree_label" 
    android:text="@string/strongly_agree_txt" 
    android:layout_below="@id/radio_group" 
    android:layout_alignParentRight="true" 
    style="@style/TextAppearance" 
    android:layout_width="wrap_content" 
    android:visibility="gone" 
    /> 
+1

をカバーあなたが添付したスクリーンショットと同じではありません。 – KarenAnne

+1

ありがとうございます。:) – KarenAnne

+1

ありがとう、私は私の髪を引っ張ってきた! – Garbit

0

私はあなたが右の質問を理解している場合、あなたはまた、ラジオグループ内の次のコードを試すことができます。

<ToggleButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<View 
    android:id="@+id/view1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 

<ToggleButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
関連する問題