微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android-在文本和imageview之间放置空格

我有以下xml.我有textview和imageview.我想在这些项目之间留一点空间(让我们说20dp),但基于textview的长度,有时会重叠.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|left"
    android:id="@+id/myName"
    android:textSize="14sp" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/myName"
    android:gravity="center_vertical|right"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_arrow_drop_down_red"
    android:paddingLeft="20dp" />
</RelativeLayout>

您还可以在下图中看到问题.有文字和图像.图像为红色.

enter image description here

更新:

我已经使用android:drawableRight遵循了以下方法,但是得到了同样的东西.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
    android:textColor="@color/primary_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|left"
    android:id="@+id/myName"
    android:textSize="14sp"
    android:drawableRight="@drawable/ic_arrow_drop_down_red"
    android:drawablePadding="20dp" />
 </RelativeLayout>

解决方法:

您可以像这样在这两个之间插入一个具有所需宽度的空视图(将布局更改为LinearLayout也可能很聪明).

编辑更改为线性布局后,空视图解决方案和drawableRight解决方案都可以使用,因此我正在编辑我的视图以使其看起来更漂亮. drawableRight的全部功劳归@JuanCortes:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|left"
    android:id="@+id/myName"
    android:textSize="14sp"
    android:drawableRight="@drawable/ic_arrow_drop_down_red"
    android:paddingLeft="20dp" />

</LinearLayout>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐