如何在android中将图像放在复选框前面。。?
如何在android中像这样将图像和复选框放在同一行中图像视图可以用于此吗?如何在android中将图像放在复选框前面。。?,android,checkbox,Android,Checkbox,如何在android中像这样将图像和复选框放在同一行中图像视图可以用于此吗? 谢谢。对每一行使用线性布局,并将它们全部放在这一行中。对每个小部件(如复选框)也使用安卓:布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" androi
谢谢。对每一行使用线性布局,并将它们全部放在这一行中。对每个小部件(如复选框)也使用安卓:布局
<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>
这很简单
使用相对布局(非常重要)。将图像放置在需要的位置(可以与父布局对齐),然后在xml中使用“向右”选项对齐图片旁边的复选框
关键元素是使用相对布局,并在您使用的xml中使用“图片id右侧”
您可以使用本教程
如果前面的意思是指右边(或左边),我认为最简单、最有效的方法是使用
android:drawableRight
(或android:drawableLeft
)属性,例如
android:drawableRight=“@drawable/my\u img”
这是有效的,因为它使用相同的视图。ok然后将
imageview
置于左侧,将复选框置于右侧
如果您想使动态,那么有一个选项可用,但它是不同的。像
这是一个很好的问题,我想知道复选框的数量是动态的还是静态的?在文本之后显示图像是否方便?这可能是最优雅的方式,但这似乎对JB不起作用。图像与复选框重叠,未放置在正确位置。你知道怎么在JB上说吗?
<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>
<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>