我希望我的TextView可以在水平方向上允许超出屏幕(同时禁用水平滚动条),就像这样:
然而,我现在的XML会导致它自动适应父元素大小,就像这样:
代码:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parentlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<TextView
android:layout_marginTop="30px"
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello1"
android:textColor="#1089F9"
android:textSize="40sp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="5dp"/>
<TextView
android:layout_marginTop="30px"
android:id="@+id/tab2"
android:layout_toRightOf="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello2"
android:textColor="#1089F9"
android:textSize="40sp"
android:layout_marginLeft="50dp"
android:layout_marginBottom="5dp"/>
<TextView
android:layout_marginTop="30px"
android:id="@+id/tab3"
android:layout_toRightOf="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello3"
android:textColor="#1089F9"
android:textSize="40sp"
android:layout_marginLeft="50dp"
android:layout_marginBottom="5dp"/>
</RelativeLayout>
我该如何更改我的代码,使布局显示为第一张图片中的样式?如果TextView超出父视图,只需将其裁剪掉即可。
编辑:尝试过LinearLayout,但也没有效果
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parentlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="horizontal">
<TextView
android:layout_marginTop="30px"
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello1"
android:textColor="#1089F9"
android:textSize="40sp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="5dp"/>
<TextView
android:layout_marginTop="30px"
android:id="@+id/tab2"
android:layout_toRightOf="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello2"
android:textColor="#1089F9"
android:textSize="40sp"
android:layout_marginLeft="50dp"
android:layout_marginBottom="5dp"/>
<TextView
android:layout_marginTop="30px"
android:id="@+id/tab3"
android:layout_toRightOf="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello3"
android:textColor="#1089F9"
android:textSize="40sp"
android:layout_marginLeft="50dp"
android:layout_marginBottom="5dp"/>
</LinearLayout>