扫描: 绘制一个扫描渐变,它将沿着父形状(通常是一个圆环)的外边界从startColor到endColor进行过渡。
示例
shape_gradient_rectangle.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 线性渐变的矩形 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:useLevel="false">
<gradient
android:startColor="#ffffff"
android:endColor="#ffffff"
android:centerColor="#000000"
android:useLevel="false"
android:type="linear"
android:angle="45"
/>
</shape>
shape_gradient_oval.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 辐射渐变的椭圆 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<gradient
android:startColor="#ffffff"
android:endColor="#ffffff"
android:centerColor="#000000"
android:useLevel="false"
android:type="radial"
android:gradientRadius="300"
/>
</shape>
shape_gradient_ring.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 扫描渐变的圆环 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:useLevel="false"
android:innerRadiusRatio="3"
android:thicknessRatio="8">
<gradient
android:startColor="#ffffff"
android:endColor="#ffffff"
android:centerColor="#000000"
android:useLevel="false"
android:type="sweep"
/>
</shape>
fragment_shap_gradient.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/shap1"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/shape_gradient_rectangle"
android:contentDescription="@string/app_name" />
<ImageView
android:id="@+id/shap2"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/shape_gradient_oval"
android:contentDescription="@string/app_name" />
<ImageView
android:id="@+id/shap3"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/shape_gradient_ring"
android:contentDescription="@string/app_name" />
</LinearLayout>
活动代码
package com.test.androidtest;
import android.app.Activity;
import android.os.Bundle;
public class ShapGradientActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_shap_gradient);
}
}
运行测试