2016-03-18 3 views
2

私はアンドロイドの開発に慣れています。アンドロイドの複数の行にラジオボタンを配置する

複数の行に6つのラジオボタンを画面に配置したいと考えています。画面サイズに基づいて、最初の行に3つのラジオボタンを入れて、2行目の最初の行を占め、次に3番目の行を占めるようにします。

xmlを書く方法を教えてください。使用するすべての電話機に一般化できるようにしてください。

+0

レイアウトXMLファイルを作成し、必要に応じて他のアクティビティレイアウトに含めることができます。 – kabuto178

答えて

0

を、あなたが探しているものを達成するための方法の一つは、相対的なレイアウトを使用することで、基本的には、

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RadioGroup 
     android:id="@+id/firstone" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <RadioButton android:id="@+id/radio_pirates" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="first" 
      android:onClick="onRadioButtonClicked"/> 
     <RadioButton android:id="@+id/radio_ninjas" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="second" 
      android:onClick="onRadioButtonClicked"/> 
     <RadioButton android:id="@+id/radio_test" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="third" 
      android:onClick="onRadioButtonClicked"/> 
    </RadioGroup> 

    <RadioGroup 
     android:id="@+id/secondone" 
     android:layout_below="@+id/firstone" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <RadioButton android:id="@+id/radio_pirate" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="first" 
      android:onClick="onRadioButtonClicked"/> 
     <RadioButton android:id="@+id/radio_ninja" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="second" 
      android:onClick="onRadioButtonClicked"/> 
     <RadioButton android:id="@+id/radio_tes" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="third" 
      android:onClick="onRadioButtonClicked"/> 
    </RadioGroup> 

</RelativeLayout> 

をこのコードをご確認ください。一方のグループを他方のグループの上に置くことができます。ラジオグループの方向も垂直または水平方向として定義できます。ラジオボタンの詳細については、http://developer.android.com/guide/topics/ui/controls/radiobutton.html

希望します。

0

あなたはアンドロイドとのGridViewを使用することができます。numColumnsのは=「auto_fit」

+0

xmlファイルの外観を教えてください。 – Minions

+0

numColumns = "auto_fit"のGridViewをxmlファイルに置き、アダプタをGridViewに設定するだけです –

関連する問題