java - 为什么这些图像按钮(删除和更新)重叠

标签 java android xml layout

此 .xml 将是 RecycleView 列表中项目的布局,但最后两个按钮重叠

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#Ffffff"


    android:baselineAligned="false"
    android:weightSum="1">

    <LinearLayout android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="3dip"
        android:layout_alignParentLeft="true"
        android:background="@drawable/favorite"
        android:layout_marginRight="5dip">

        <ImageButton
            android:id="@+id/imageButton"
            android:layout_width="25dip"
            android:layout_height="25dip"
            android:background="@null"
            android:src="@drawable/nofavorite"/>

    </LinearLayout>


    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thumbnail"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="Rihanna Love the way lie"
        android:textColor="#040404"
        android:typeface="sans"
        android:textSize="15dip"
        android:textStyle="bold"/>
    <TextView
        android:id="@+id/artist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#343434"
        android:textSize="10dip"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="Just gona stand there and ..."
        android:layout_below="@+id/text_view" />


    <ImageButton android:layout_width="wrap_content"
        android:id="@+id/update"
        android:layout_height="wrap_content"
        android:src="@drawable/nofavorite"
        android:background="@null"
        android:layout_alignRight="@+id/artist" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:id="@+id/delete"
        android:src="@drawable/favorite"
        android:layout_alignRight="@+id/artist"
        />


</RelativeLayout>

它们应该位于右侧的末尾,最后是“删除”按钮,位于该按钮的左侧,但在屏幕的右端是“更新”按钮,我稍后会将某些内容绑定(bind)到该按钮

还有一个问题,我如何在项目之间制作分隔线?

谢谢=)

最佳答案

这是因为您在两个图像上使用 layout_alignRight="@+id/artist" ,这基本上将两个图像的右边缘与具有 id 艺术家的 View 的右边缘对齐。要实现您想要的效果,请在 DELETE 按钮上使用 layout_alignParentRight="true" ,在 UPDATE 按钮上使用 layout_toLeftOf="@+id/delete" 。顺便说一下,为什么父级上需要layout_weightSum。它仅适用于 LinearLayout。

要在项目之间创建分隔线,您可以在其中一个项目上使用带有左(右)边框的背景,或者在它们之间放置一个 View 。

关于java - 为什么这些图像按钮(删除和更新)重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30928444/

相关文章:

java - 为什么这个方法不起作用?

java - 从 Google 托管虚拟机(自定义/Java)连接到 Google Cloud 数据存储?

android - 将 CookieManager 添加到 android Childbrowser

android - 如何在android中搜索twitter.com/search并解析数据

android - 如何动态创建一个按钮?

xml - 如何在元素中检测文本节点

java - Intellij maven结构

Java 大十进制问题

Android - 异常错误膨胀类 com.facebook.drawee.view.SimpleDraweeView

java - 在 ANT 的 Build.xml 中找不到类名下提到的类