2011-07-15 3 views
3

このiamgeのようにアンドロイドの同じ行に画像とチェックボックスを入れる方法enter image description hereこれを表示するには画像を使用できますか?おかげさまで アンドロイドのチェックボックスの前にイメージを置く方法..?

+0

のように、これは良い質問ですが、私は、チェックボックスの数が動的または静的で知りたいのですが? –

+0

テキストの後に画像を表示するのは便利ですか? –

+0

チェックボックスは静的です。 – Miuranga

答えて

1
各行に対する

使用リニアレイアウトと、これはまた、チェックボックスのように各ウィジェットのためandroid:layout_toRightOfを利用するには、それらのすべてを置くが、TextViewに使用などはこの

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:orientation="vertical"> 
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/layout1"> 
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/im1"/> 
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ck1" android:layout_toRightOf="@+id/im1"/> 
<TextView android:text="hi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txt1" android:layout_toRightOf="@+id/ck1"/> 
</LinearLayout> 

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/layout2" android:layout_below="@id/layout1"> 
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/im2"/> 
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ck1" android:layout_toRightOf="@+id/im2"/> 
<TextView android:text="hello" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txt1" android:layout_toRightOf="@+id/ck2"/> 
</LinearLayout> 
</RelativeLayout> 
3

それは非常に簡単です。

ララティブレイアウトを使用する(非常に重要)。あなたが望むところにあなたのイメージを置き(あなたはそれを親レイアウトと合わせることができます)、xmlの 'to right of'オプションを使ってピクチャの横にあるチェックボックスを合わせます。

重要な要素は、相対レイアウトを使用し、使用するxmlの[画像のID]の右に使用することです。

このチュートリアルを使用できます。フロントであなたが実際に右に意味(または左)場合

http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-relative-layouts/

2

私は、最も簡単で最も効率的な方法は、例えばandroid:drawableRight(またはandroid:drawableLeft)属性を使用することだと思う

android:drawableRight="@drawable/my_img"

<CheckBox 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:id="@+id/my_checkBox1" 
    android:drawableRight="@drawable/my_img" 
    android:text="Option_Text"> 
</Checkbox> 

これは同じビューを使用するので効率的です。 OK

+0

これはおそらく最もエレガントな方法ですが、JBにはうまくいかないようです。イメージがチェックボックスに重なり、正しい場所に置かれません。どのようにJB上でそれにどのようなアイデア? – Muzikant

3

はその後imageview左側を入れて、あなたはダイナミックで、その後1つのオプションが利用可能ですが、それは異なる終了されていることを確認したい場合は、チェックボックスの右側 を置きます。
​​

<CheckBox android:layout_height="wrap_content" 
android:id="@+id/checkBox1" android:layout_width="wrap_content" 
android:drawableRight="@drawable/icon" android:text="CheckBox" android:layout_x="58dip" android:layout_y="106dip"></CheckBox> 
関連する問題