当文本较大且正在滚动时,不显示 TextView Shape 背景
TextView Shape background is not showing when text is large and is scrolling
这是问题场景:
我有一个 Activity
包括一个 ScrollView
,
ScrollView
小时候只有一个 LinearLayout
而 LinearLayout
有一个 TextView
。
XML 文件在这里:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bubble_shape"
android:text="@string/TestLargeText"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
"bubble_shape" drawable
在这里:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp"/>
<stroke
android:width="8dp"
android:color="#ff00ff"/>
</shape>
我在 TextView
中有一大段文字,问题在于:
当 TextView
有大文本时,背景形状不显示。您可以在下面的图片中看到问题:
我该如何解决这个问题?
我用两种方法解决了你的问题。
1- 将 "bubble_shape" 设置为您的 HorizontalScrollView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bubble_shape">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/TestLargeText" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
2- 或者像这样更改 "bubble_shape" 中的角标记:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="15dp" />
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp" />
<stroke
android:width="8dp"
android:color="#ff00ff" />
</shape>
这是问题场景:
我有一个 Activity
包括一个 ScrollView
,
ScrollView
小时候只有一个 LinearLayout
而 LinearLayout
有一个 TextView
。
XML 文件在这里:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bubble_shape"
android:text="@string/TestLargeText"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
"bubble_shape" drawable
在这里:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp"/>
<stroke
android:width="8dp"
android:color="#ff00ff"/>
</shape>
我在 TextView
中有一大段文字,问题在于:
当 TextView
有大文本时,背景形状不显示。您可以在下面的图片中看到问题:
我该如何解决这个问题?
我用两种方法解决了你的问题。
1- 将 "bubble_shape" 设置为您的 HorizontalScrollView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bubble_shape">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/TestLargeText" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
2- 或者像这样更改 "bubble_shape" 中的角标记:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="15dp" />
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp" />
<stroke
android:width="8dp"
android:color="#ff00ff" />
</shape>