提问人:YUNG FOOK YONG 提问时间:11/13/2023 更新时间:11/13/2023 访问量:37
将 textview 放在按钮的左侧,直到 toLeftTo,但也将文本向左对齐
Place textview on the left of button through toLeftTo but also align text to the left
问:
下面是一个简单的UI设计,我通过设置Description属性来设置Description属性,使其保持在按钮的左侧,否则如果描述太长,文本将被按钮挡住。我想使描述文本向左对齐。我试过改变,但没有用。android:toLeftTo
android:layout_gravity
下面是 UI 段的 XML 代码。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/requestRl"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="10dp"
android:layout_below="@id/requestTv"
android:background="@drawable/rounded_field">
<TextView
android:id="@+id/dateTv"
android:textSize="13sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="Appointment Time: "
android:maxLines="1"/>
<TextView
android:id="@+id/descriptionTv"
android:textSize="13sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/cancelBtn"
android:layout_below="@id/dateTv"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="Description: "/>
<TextView
android:id="@+id/statusTv"
android:textSize="13sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/descriptionTv"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="Comment: " />
<Button
android:id="@+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="Cancel"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/rounded_field"
android:backgroundTint="#ff7f7f"
android:textAllCaps="false"/>
</RelativeLayout>
答:
0赞
Pawan Harariya
11/13/2023
#1
若要对齐视图,可以使用属性。可以使说明的起点与 TextView using 属性的起点对齐。align
dateTv
layout_alignStart
您还可以从开头删除边距并在末尾添加边距。
<TextView
android:id="@+id/descriptionTv"
android:textSize="13sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/cancelBtn"
android:layout_alignStart="@id/dateTv"
android:layout_below="@id/dateTv"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:text="Description: "/>
示例输出:
评论