利用shape绘制渐变背景

J简文

关注

阅读 66

2022-02-27


  1. 线性渐变
    如从左到右,从上到下等

  • 效果图:
    利用shape绘制渐变背景_android
  • 代码:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#2193b0"
android:endColor="#6dd5ed"
android:angle="90"/>
<corners android:radius="4dp"/>
</shape>
  1. 放射性渐变

  • 效果图:
    利用shape绘制渐变背景_5e_02
  • 代码:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#2193b0"
android:endColor="#6dd5ed"
android:gradientRadius="150"
android:type="radial"
android:angle="90"/>
<corners android:radius="4dp"/>
</shape>
  1. 扫描式渐变

  • 效果图:
    利用shape绘制渐变背景_5e_03
  • 代码:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#2193b0"
android:endColor="#6dd5ed"
android:type="sweep"
android:angle="90"/>
<corners android:radius="4dp"/>
</shape>

Demo源代码

https://github.com/cxyzy1/gradientShapeDemo

附录

关于Android shape gradient背景渐变



精彩评论(0)

0 0 举报