我需要布局显示:Android的布局:在TextView的右侧的TextView
- 如果cl__tv_team_name有简短的文字,它显示(Q)签署旁边 cl__tv_team_name(cl__tv_team_name和(Q)符号彼此相邻)
- 如果cl__tv_team_name有长文本,textview显示它有两个或更多行,但(Q)符号是仍然可见在右侧
简单LinearLayout
不起作用。 TextView cl__tv_team_name需要所有宽度。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/cl__tv_team_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" />
<TextView
android:id="@+id/cl__tv_q_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(Q)" />
</LinearLayout>
我还试图RelativeLayout
没有适当的效果:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:id="@+id/cl__tv_team_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/cl__tv_team_name"
android:layout_toRightOf="@+id/cl__tv_team_name"
android:text="(Q)"
android:textSize="13sp" />
</RelativeLayout>
这就是我想要实现的。我没有时间学习约束布局,所以感谢你的代码。 – AppiDevo
还有一个问题,是否可以垂直居中(Q)?所以它会被放置在第一个视图的第一行和第二行之间。 – AppiDevo
是的。通过将'q'的顶部限制在'text'的顶部,并将其底部限制到'text'底部来实现。删除基线约束。 –