2017-03-22 14 views
0

で、プログラムラジオボタンを追加します。アンドロイドXamarin:私はこのような何かを構築しようとしています色

RadioButtons

私のアプリは、質問・回答の配列を取得します。答えごとに、ラジオボタンをプログラム的に作成する必要があります(図のラジオボタンの例では4つです)。

私の最初の質問は、あなたはRadioButtonsで作業するのですか、別の回避策がその仕事をより良くすると思いますか?

私の2番目の質問:各ラジオボタンの色を変更することは可能ですか、どのように各ラジオボタンに小さなビューを与えることができますか、バックグラウンドカラーを設定できますその後、色やラジオボタンのテキスト)で

たぶん、あなたは私を助けることができます:)

答えて

0

だから私の最初の質問は、あなたがラジオボタンで仕事をしたりするだろうあなたは別の問題を回避するには、仕事をするだろうと思いますより良い?

はい、RadioButtonがこの仕事に当てはまります。

それははい、それは可能であり、各ラジオボタン

の色を変更することが可能です。 android:buttonのドロウアブルリソースをRadioButtonに設定するだけです。もし

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_checked="false"> 
    <layer-list> 
     <item android:height="25dp" android:width="25dp"> 
     <shape android:shape="oval"> 
      <gradient 
       android:startColor="#E0FFCD" 
       android:endColor="#42FAA1" 
       android:angle="45" /> 
      <stroke android:width="2dp" 
        android:color="#000000" /> 
     </shape> 
     </item> 
    </layer-list> 
    </item> 
    <item android:state_checked="true"> 
    <layer-list> 
     <item android:height="25dp" android:width="25dp"> 
     <shape android:shape="oval"> 
      <gradient 
       android:startColor="#E0FFCD" 
       android:endColor="#42FAA1" 
       android:angle="45" /> 
      <stroke android:width="2dp" 
        android:color="#2d1717" /> 
     </shape> 
     </item> 
     <item android:height="10dp" android:width="10dp" 
      android:gravity="center"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#000000" /> 
     </shape> 
     </item> 
    </layer-list> 
    </item> 
</selector> 

:例えば:

<RadioGroup android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:orientation="vertical" 
      android:layout_marginLeft="5dp"> 
    <RadioButton android:id="@+id/ware1" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="@string/Ware1" 
       android:button="@drawable/gradient" 
       android:paddingLeft="8dp" /> 
    <RadioButton android:id="@+id/ware2" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="@string/Ware2" /> 
    <RadioButton android:id="@+id/ware3" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="@string/Ware3" /> 
    <RadioButton android:id="@+id/ware4" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="@string/Ware4" /> 
</RadioGroup> 

私は最初RadioButtonのためのセレクタを作成し、このボタンの背景色がグラデーションで、あなたは一例として、これを取るとあなたを作成することができますとにかく、RadioButtonごとにセレクタを作成する必要があり、セレクタはcheckeduncheckedの状態がRadioButtonであるため、各ボタンのシェイプを作成するには手間がかかります。

+0

お返事ありがとうございました:) これは私を助けました。最後に、私は 'ラジオボタンで しかしを働いています[i]を.SetCompoundDrawablesRelativeWithIntrinsicBounds(正方形、NULL、NULL、NULL);' とほんの少しの白い四角を使用し、私は必要なので、色に濃淡を設定これを動的に変更します。 –

関連する問題