Android layout
CheckBox(チェックボックス)とRadioGroup(ラジオグループ)
プロジェクト(HelloAndroid)からres→layout→main.xmlを開きます。
レイアウトタブでビューからCheckBoxを黒い画面にドラッグします。
次にビューの中にRadioButtonがありますが、RadioButtonを単独で使用することはないと思われますので、RadioGroupの設定を記述します。
今度はビューではなくレイアウトからRadioGroupを黒い画面にドラッグします。
作成したRadioGroupにRadioButtonを設定します。今度はビューにあるRadioButtonを要素として必要分だけ黒い画面にドラッグします。
その後Eclipseのアウトラインにある「↑」「↓」を使用して所定の場所に移動させます。下図を参考にして試してください。
main.xmlタブでソースを確認します。
<CheckBox android:text="@+id/CheckBox01"
android:id="@+id/CheckBox01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
CheckBox>
<RadioGroup android:id="@+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:text="@+id/RadioButton01"
android:id="@+id/RadioButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
RadioButton>
<RadioButton android:text="@+id/RadioButton02"
android:id="@+id/RadioButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
RadioButton>
RadioGroup>
ソース解説
内容としてはテキストボックスと設定方法は同じです。
項目の並び等はレイアウトとしてまとめて後ほど解説します。
今回は以下のように修正してみました。(アンダーライン部分)
<CheckBox android:text="Androidに興味がある?"
android:id="@+id/ck_android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
CheckBox>
<RadioGroup android:id="@+id/rg_sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:text="男性"
android:id="@+id/rb_man"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
RadioButton>
<RadioButton android:text="女性"
android:id="@+id/rb_woman"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
RadioButton>
RadioGroup>
実行結果は下図のようになります。
RadioGroupにtextを付けれないのが“?”です。内部処理では「android:id="@+id/rg_sex」があるから問題ないと思いますがユーザーインタフェースとしては、別途TextViewを入れないといけませんね。
0 件のコメント:
コメントを投稿