Android LinearLayout容器中TextView宽度超出容器宽度也正常绘制超出部分看不到没关系怎么做?
要实现这个效果,你可以在LinearLayout容器中添加一个TextView,并将其宽度设置为超出容器宽度。然后,你可以使用以下两种方法来实现超出部分看不到的效果:
- 使用
android:clipChildren="false"属性:在LinearLayout容器中添加该属性,可以让容器的子视图超出容器的边界而不被裁剪。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clipChildren="false">
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="超出容器宽度的文本"
android:singleLine="true" />
</LinearLayout>
- 使用
android:scrollHorizontally="true"属性:在TextView中添加该属性,可以让文本在水平方向上滚动,超出容器宽度的部分会自动隐藏。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="超出容器宽度的文本"
android:singleLine="true"
android:scrollHorizontally="true" />
</LinearLayout>
以上两种方法可以根据你的实际需求选择其中一种来实现超出部分看不到的效果
原文地址: https://www.cveoy.top/t/topic/iapD 著作权归作者所有。请勿转载和采集!