android– 相对布局,对齐父视图和右视图的中心,没有重叠

android– 相对布局,对齐父视图和右视图的中心,没有重叠,第1张

概述我试图将TextView对齐在相对布局中,但也在ImageView的右侧.我希望它看起来像这样.[-(image)-----sometexthere------------]我可以使用下面的代码执行此 *** 作,但如果文本变得太长,则会与图像重叠.<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="ht

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

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

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

<?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="wrap_content"    androID:orIEntation="horizontal"    androID:paddingtop="@dimen/small_padding"    androID:paddingBottom="@dimen/small_padding"    androID:background="@color/White">    <ImageVIEw        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" />    <TextVIEw        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" /></relativeLayout>

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

解决方法:

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

<RadioGroup                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal"                androID:layout_gravity="center"                androID:paddingtop="20dp">                    <Radiobutton                        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"/>                    <Radiobutton                        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"/>            </RadioGroup>

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

总结

以上是内存溢出为你收集整理的android – 相对布局,对齐父视图和右视图的中心,没有重叠全部内容,希望文章能够帮你解决android – 相对布局,对齐父视图和右视图的中心,没有重叠所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存