【发布时间】:2011-07-15 13:51:23
【问题描述】:
如何将图像和复选框放在 android 中的同一行中,像这样 iamge 可以使用图像视图吗? 谢谢。
【问题讨论】:
-
这是个好问题,我想知道复选框的数量是动态的还是静态的?
-
文字后显示图片方便吗?
如何将图像和复选框放在 android 中的同一行中,像这样 iamge 可以使用图像视图吗? 谢谢。
【问题讨论】:
这很简单。
使用相对布局(非常重要)。将您的图像放置在您想要的位置(您可以将其与父布局对齐),然后使用 xml 中的“向右”选项对齐图片旁边的复选框。
关键元素是使用相对布局并在您使用的 xml 中使用“[图片的 id] 右侧”。
您可以使用本教程。
http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-relative-layouts/
【讨论】:
好的
然后把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>
【讨论】:
如果前面实际上是指右侧(或左侧),我认为最简单和最有效的方法是使用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>
这很有效,因为它使用相同的视图。
【讨论】:
对每一行使用线性布局并将它们全部放入其中还为每个小部件使用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>
【讨论】: