我想知道如何在 xml 中创建这个背景, 找不到任何对我有帮助的东西。
当然忽略 child 的圆圈图像和文字,我说的是背景本身,有没有办法在 xml 中创建类似的东西?
在此先感谢您的帮助。 干杯!
最佳答案
我猜你继续前进,但你可以使用 Vector Drawables 来做到这一点.
以下是不准确的(线不是完全直的),但应该给你一个好的开始:
新的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="100dp"
android:width="100dp"
android:viewportHeight="100"
android:viewportWidth="100">
<path
android:name="dark_triangle"
android:fillColor="@color/blue"
android:pathData="M 0,100 L 0,80 60,70 100,80 100,100 z" />
<path
android:name="light_triangle"
android:fillColor="@color/color_light_blue"
android:pathData="M 60,70 L 100,65 100,80 z" />
</vector>
在你的布局中:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
app:srcCompat="@drawable/test"
/>
您可能还需要将此添加到您的布局中:
xmlns:app="http://schemas.android.com/apk/res-auto"
注意事项:
- 如果有人感兴趣,可以提供更多资源:1 2 .
- There's a preview for Vector Drawables in Android Studio .
- 矢量绘图已在 API 21 中引入,但应在 older APIs 中得到支持.
关于Android - 具有不同颜色和角度的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44430426/