我需要绘制如下图所示的类别路径,问题是项目形状
实现这一目标的最佳实践是什么?
我可以考虑几个选项,例如:
- 扩展 TextView 并更改其形状
- 添加矢量可绘制背景
- 添加 xml 可绘制背景
有什么想法吗?
最佳答案
以下是我的理解:
- Extending TextView and changing it shape
这将在运行时加载 TextView,因此不会节省内存。
- Adding vector drawable background
这是一个很好的做法。但 native Vector 可绘制支持是从 API 级别 21 开始的。要支持较低的 api 设备,您需要添加 vectorDrawables.useSupportLibrary = true
并将 build.gradle
文件修改为:
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
Android Studio 1.4+ 将在构建时生成 png。
- Adding xml drawable background
这将支持所有版本和最简单的解决方案。
My suggestion will be to use Vectordrawables. This will give the best support with different Android versions.
关于android - 在 RecyclerView 中绘制自定义 TextView 路径的最佳实践是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56555571/