How to put image and 开发者_开发问答check box in same line in android like this iamge
can image view use for this ? Thanks.It is quite simple.
Use ralative layout(Very important). Place your image where you want it(you can align it w.r.t the parent layout) and then use 'to right of' option in your xml to align the checkbox next to the picture.
Key elements are to use relative layout and to use 'to right of [the picture's id]' in the xml you use.
You can use this tutorial.
http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-relative-layouts/
ok
then put imageview
left side and put checkbox right side
if you would like to make dynamic then one option are available but it is quit different. like
<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>
If by front you actually mean to the right (or left of) I think the simplest and most efficient way would be to use the android:drawableRight
(or android:drawableLeft
) attribute e.g.,
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>
This is efficient as it uses the same view.
Use Linear Layout for each row and put all of them in to this also use android:layout_toRightOf
for each widget like checkbox, Textview Use Like This
<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>
精彩评论