i_m*_*ine 5 android relativelayout
我试图将TextView对齐在相对布局的中心,但也要对齐ImageView的右边。我希望它看起来像这样。
[-(image)-----some text here------------]
Run Code Online (Sandbox Code Playgroud)
我可以使用以下代码执行此操作,但是如果文本太长,则会与图像重叠。
<?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>
Run Code Online (Sandbox Code Playgroud)
我已经尝试将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>
Run Code Online (Sandbox Code Playgroud)
编辑:我不知道我在文本视图上使用的按钮的边距属性是否有效,但文本上的左侧填充可能有效
| 归档时间: |
|
| 查看次数: |
1515 次 |
| 最近记录: |