【问题标题】:CheckBox widget in the top right corner of an image图像右上角的 CheckBox 小部件
【发布时间】:2016-10-19 02:45:03
【问题描述】:

目前我正在通过 Picasso 每行下载 2 张图片。我想在它们每个的右上角添加一个复选框。应该如何定义复选框?到目前为止的布局如下:

<!--Row1-->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:orientation="horizontal"
    android:layout_weight="1">

        <ImageView
            android:id="@+id/img1"
            style="@style/singleImage"
            android:layout_marginRight="10dp"/>


        <ImageView
            android:id="@+id/img2"
            style="@style/singleImage"/>
</LinearLayout>

还有风格:

<style name="singleImage">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_weight">1</item>
</style>

【问题讨论】:

  • 首先在布局上添加 2 个 CheckBox,然后使用 RelativeLayout 进行分组(ImageView_1 和 CheckBox_1)&(ImageView_2 和 CheckBox_2)
  • 好的,但是如何对齐它们并使它们出现在图像上?按照您的建议,他们只是替换了图片。
  • &lt;RelativeLayout ... &gt; &lt;ImageView ... /&gt; &lt;CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="" /&gt; &lt;/RelativeLayout&gt;
  • 使用LinearLayout添加RelativeLayout后,图片无法从服务器下载,也无法显示。

标签: android image checkbox picasso clickable


【解决方案1】:

我的评论是这样的:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="horizontal">

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <ImageView
            android:id="@+id/img1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp" />

        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <ImageView
            android:id="@+id/img2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_weight="1" />

        <CheckBox
            android:id="@+id/checkBox2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="" />
    </RelativeLayout>
</LinearLayout>

【讨论】:

  • 哦,现在我明白了!非常感谢,太好了!
猜你喜欢
  • 1970-01-01
  • 2012-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多