android - 当文本很大并且正在滚动时,TextView Shape 背景不显示
问题描述
这是问题场景:
我有一个,Activity
包括一个ScrollView
,
小时候ScrollView
只有一个,而有一个。XML 文件在这里:LinearLayout
LinearLayout
TextView
<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>
推荐阅读
- c# - C# Windows 窗体 ToolStrip 和 MenuStrip 内存泄漏
- kubernetes - Kubernetes 托管 Auto Scaling 组如何启用指标收集
- git - 如何将源(本地)存储库中的更新(最后几次提交)与使用 git subtree 创建的子目录合并?
- linux - 比较来自多个文件的列值
- python - Python中带有AND条件的LOC搜索字符串
- node.js - 无法读取未定义的属性“forEach”,nodeJS mongoose ejs
- node.js - SAP Business One -> 嵌入式事件的 Rest API
- maven - 无法在项目 SydApp 上执行目标 org.openjfx:javafx-maven-plugin:0.0.6:run (default-cli):错误
- swift - ARKit 对象 2D x, y 位置
- android - 从 Android Kotlin 加密芯片迁移到 Flutter Dart