我希望我的 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>
最佳答案
尝试在您的 3 TextView 上使用此属性
android:maxLines="1"
设置 maxLines="1"后我得到了这个结果
关于android - 允许 TextView 在屏幕之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31503928/