2011-07-15 27 views
3

如何把图像和复选框安装在同一行中像这样的iamge enter image description here可以使用图像查看这个吗? 谢谢。如何把图像放在android ..的复选框前面?

+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> 
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> 

这是有效的,因为它使用相同的视图。

+0

这可能是最优雅的方式,但它似乎不适用于JB。图像与复选框重叠,未放置在正确的位置。任何想法如何在JB上? – Muzikant

3

确定
然后把imageview左侧,把复选框右侧 如果您想进行动态再一个选项也有,但它是不干不同。像
​​

<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>