android相对布局的界面元素如何自适应,且不相互重叠,android – 相对布局,对齐父视图和右视图的中心,没有重叠...

我试图将TextView对齐在相对布局中,但也在ImageView的右侧.我希望它看起来像这样.

[-(image)-----some text here------------]

我可以使用下面的代码执行此操作,但如果文本变得太长,则会与图像重叠.

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:paddingTop="@dimen/small_padding"

android:paddingBottom="@dimen/small_padding"

android:background="@color/White">

android:id="@+id/navMenu"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/home_icon"

android:layout_marginEnd="@dimen/small_padding"

android:contentDescription="@string/abc_search_hint"

android:layout_alignParentStart="true" />

android:id="@+id/actionBarTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/profile"

android:textSize="24sp"

android:textStyle="bold"

android:textColor="@color/Black"

android:maxLines="1"

android:ellipsize="end"

android:contentDescription="@string/title_activity_connect"

android:layout_centerInParent="true" />

我已经尝试将TextView对齐到ImageView的右侧,但如果我这样做,它会停止在父级中心.任何帮助表示赞赏

解决方法:

你可以尝试这样的事情.为此,我使用了一个无线电组而不是线性布局,但它仍然可以工作.将线性布局水平放置,然后使布局重心,然后将图像放在文本视图之前

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_gravity="center"

android:paddingTop="20dp">

android:id="@+id/radio_student"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/checkbox_student"

android:onClick="onRadioButtonClicked"

android:layout_marginEnd="30dp"

android:layout_marginRight="30dp"/>

android:id="@+id/radio_teacher"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/checkbox_teacher"

android:onClick="onRadioButtonClicked"

android:layout_marginStart="30dp"

android:layout_marginLeft="30dp"/>

编辑:

我不知道按钮的边距属性是否可用于文本视图,但文本视图上的填充可能有效

标签:android,relativelayout

来源: https://codeday.me/bug/20190708/1400220.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值