【问题标题】:How to put image in front of check box in android ..?如何将图像放在 android 中的复选框前面 ..?
【发布时间】:2011-07-15 13:51:23
【问题描述】:

如何将图像和复选框放在 android 中的同一行中,像这样 iamge 可以使用图像视图吗? 谢谢。

【问题讨论】:

  • 这是个好问题,我想知道复选框的数量是动态的还是静态的?
  • 文字后显示图片方便吗?

标签: android checkbox


【解决方案1】:

这很简单。

使用相对布局(非常重要)。将您的图像放置在您想要的位置(您可以将其与父布局对齐),然后使用 xml 中的“向右”选项对齐图片旁边的复选框。

关键元素是使用相对布局并在您使用的 xml 中使用“[图片的 id] 右侧”。

您可以使用本教程。

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

【讨论】:

    【解决方案2】:

    好的
    然后把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>
    

    【讨论】:

      【解决方案3】:

      如果前面实际上是指右侧(或左侧),我认为最简单和最有效的方法是使用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>
      

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

      【讨论】:

      • 这可能是最优雅的方式,但似乎这不适用于 JB。图像与复选框重叠,并且未放置在正确的位置。知道如何在 JB 上做到这一点吗?
      【解决方案4】:

      对每一行使用线性布局并将它们全部放入其中还为每个小部件使用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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-07
        • 2015-11-18
        • 1970-01-01
        • 2014-01-10
        • 1970-01-01
        • 2011-12-30
        • 2022-08-19
        • 1970-01-01
        相关资源
        最近更新 更多