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

android-在文本和imageview之间放置空格,第1张

概述我有以下xml.我有textview和imageview.我想在这些项目之间留一点空间(让我们说20dp),但基于textview的长度,有时会重叠.<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:local="http://

我有以下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>

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

更新:

我已经使用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>
总结

以上是内存溢出为你收集整理的android-在文本和imageview之间放置空格全部内容,希望文章能够帮你解决android-在文本和imageview之间放置空格所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1120766.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存