我试图将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