我对齐两个 TextView,但当第一个 TextView 在 Android 应用程序中具有长行时,第二个 TextView 无法正确显示
我想对齐两个 TextView 并将第二个 TextView 放置在 Android 应用程序屏幕的右侧。 但第二个与外部屏幕被切断。 如果我在第一个 TextView 上写一条短信,第二个 TextView 会正确显示。
这是我的xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/Txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:textSize="17dp"
android:text="Hi, this line is long and affects right side " />
<TextView
android:id="@+id/Txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/Txt1"
android:gravity="right"
android:maxLines="1"
android:padding="12dp"
android:text="Hello world"
android:textSize="15dp" />
</RelativeLayout>
I want to align two TextViews and place the second one in the right side of the screen in Android app.
But the second one gets cut off from outside screen.
If I write a short message on the first TextView, the second one shows up correctly.
Here is my xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/Txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:textSize="17dp"
android:text="Hi, this line is long and affects right side " />
<TextView
android:id="@+id/Txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/Txt1"
android:gravity="right"
android:maxLines="1"
android:padding="12dp"
android:text="Hello world"
android:textSize="15dp" />
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西可以工作。在线性布局中使用布局权重。
Something like this could work. Using layout weight in linear layout.