一種のラベルである RadioGroup の横にテキストを表示したいと思います。したがって、RadioGroup にはテキストを含む 2 つのボタンがあり、現在、上部のみを揃えることができますが、これはかなりぎこちなく見えます。TextView を一列に並べようとすることはできますが、それは理想的でも簡単でもありません。RadioGroup と TextView は RelativeLayout 内に存在android:layout_alignBaseline
します。RadioGroup と RadioButton の 1 つを使用して TextView を試しましたが、RadioGroup にベースラインがあるようには見えず、ベースラインを取得できないようですTextView の RadioButton。
6634 次
3 に答える
2
私は最近同じ問題を抱えていましたが、ついに解決しました。私は頭に浮かんだすべての組み合わせを試しましたが、最終的には、そのトリックは TextViews に同じ値を持つ android:layout_weight を配置することにあることがわかりました。これにより、RadioButtons のちょうど中央に配置されます。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_marginLeft="15dip"
android:orientation="horizontal" >
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/radio_button"
android:paddingRight="15dip"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/radio_button"
android:paddingRight="15dip"
/>
</RadioGroup>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/cop_radiobutton_label"
android:layout_weight="1"
android:gravity="center_vertical"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/thief_radiobutton_label"
android:layout_weight="1"
android:gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
于 2012-09-05T19:13:30.360 に答える
1
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width= "fill_parent"
android:layout_height= "50dip"
android:orientation="horizontal"
android:layout_gravity="center"
android:background="@drawable/squareback">
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/meleeRadio"
android:layout_width="150dip"
android:layout_height="40dip"
android:checked="false"
android:text="Melee Attack" android:textColor="@color/black" android:gravity="center" android:layout_gravity="center" android:layout_margin="5dip"/>
<RadioButton
android:id="@+id/rangeRadio"
android:layout_width="150dip"
android:layout_height="40dip"
android:text="Range Attack" android:textColor="@color/black" android:gravity="center" android:layout_gravity="center" android:layout_margin="5dip" android:checked="false"/>
</RadioGroup>
</LinearLayout>
それらを整列させるために、サイズを設定した LinearLayout に配置します。次に、アイテムの中心を揃える android:layout_gravity="center" を実行します。そのため、ボタンとテキストのサイズは同じではありませんが、見栄えは良いです。
于 2012-04-20T18:02:02.850 に答える