android - 对齐相对布局内的复选框

标签 android gridview checkbox android-relativelayout

我有 gridview,我在网格中加载了一个图像,还有一个复选框来选择该图像。我使用 .9 图像作为背景来显示每个图像的边框。图像和复选框位于相对布局内。现在我已经尝试了所有方法,但复选框不会与边框对齐。边框和复选框总是有空格。这是为每个图像加载到网格中的 View

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageLayout"
android:gravity="top" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/back"
        android:layout_gravity="center">
    </ImageView>

    <CheckBox
        android:id="@+id/checkbox"
        android:button="@xml/checkbox" 
        android:background="@xml/checkbox_background"
        android:layout_alignRight="@id/imageLayout"
        android:layout_alignParentRight="true" android:layout_height="wrap_content" android:layout_width="wrap_content" >

    </CheckBox>
</RelativeLayout>

有什么办法吗?附上屏幕截图

编辑:我使用的背景图片设置为 imageview 背景

最佳答案

替换

android:layout_alignRight="@id/imageLayout" 

android:layout_alignRight="@id/image"

我认为您在这里犯了一个错误,因为 CheckBox 不能与其父相对布局的右侧对齐。

关于android - 对齐相对布局内的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6504720/

相关文章:

android - 如何使用 CMake 在 Android Studio 3.2 中创建静态库(.a 文件)

java - Android GridView 重绘问题

android - 在 GridView 中多次(>120 次)调用 getView 导致的 OutOfMemoryError

android - 立即验证检查 edittext 字段的输入(整数类型)

android - 模拟器不给出错误,但设备在 putExtra() 上给出 java.lang.NullPointerException

java - Android Gridview 带按钮平滑滚动

css - 具有不确定状态的三状态复选框插件作为问号

javascript - 使用 JS 或 Jquery 将复选框和单选框的值添加到标签

android - 如何在android中声明一个复选框数组

android - 如何从android中的 Assets 文件夹设置背景图片?