配置
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.ha.testvector"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary=true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
searchbar.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="150dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="150">
<path
android:name="search"
android:pathData="M141,17 A9,9 0 1,1 142,16 L149,23"
android:strokeAlpha="0.8"
android:strokeColor="#000000"
android:strokeLineCap="round"
android:strokeWidth="2"/>
<path
android:name="bar"
android:pathData="M0,23 L149,23"
android:strokeAlpha="0.8"
android:strokeColor="#000000"
android:strokeLineCap="square"
android:strokeWidth="2"/>
</vector>
bar动画文件
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:androd="http://schemas.android.com/apk/res/android"
androd:duration="1000"
androd:propertyName="trimPathStart"
androd:repeatCount="infinite"
androd:repeatMode="reverse"
androd:valueFrom="0"
androd:valueTo="1"
androd:valueType="floatType">
</objectAnimator>
search动画文件
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:androd="http://schemas.android.com/apk/res/android"
androd:duration="1000"
androd:propertyName="trimPathEnd"
androd:repeatCount="infinite"
androd:repeatMode="reverse"
androd:valueFrom="0"
androd:valueTo="1"
androd:valueType="floatType">
</objectAnimator>
动画粘合剂文件
<?xml version="1.0" encoding="utf-8"?>
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/searchbar">
<target
android:animation="@animator/anim_search"
android:name="search"/>
<target
android:animation="@animator/anim_bar"
android:name="bar"/>
</animated-vector>
布局文件
<ImageView
android:onClick="anim"
app:srcCompat="@drawable/searchbar_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>