代码库/搜索栏自定义动画(待优化)/AnimatedVectorDrawable

AnimatedVectorDrawable(粘合剂)

    用于粘合SVG和动画


MainAc

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.button);
        iv = (ImageView) findViewById(R.id.iv);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Animatable)iv.getDrawable()).start();
            }
        });
    }
}

anim_search

tips:trimPathStarts属性可以像画出一个圆一样来绘制一个圆

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="400"
    android:propertyName="trimPathStart"
    android:valueFrom="1"
    android:valueTo="0"
    android:valueType="floatType"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">
</objectAnimator>

search.xml(drawable)

创建基于xml的SVG图形

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="160dp"
    android:height="30dp"
    android:viewportHeight="30"
    android:viewportWidth="160">
    <path
        android:name="search"
        android:pathData="M141,17  A 9,9 0 1,1 142,16 L149,23"
        android:strokeColor="#ff3570be"
        android:strokeWidth="2"
        android:strokeLineCap="round"
        android:strokeAlpha="0.8"/>

    <path
        android:name="line"
        android:pathData="M0,23 L149,23"
        android:strokeColor="#ff3570be"
        android:strokeWidth="2"
        android:strokeLineCap="square"
        android:strokeAlpha="0.8"
        />

</vector>


AnimatedVectorDrawable

 
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:drawable="@drawable/search"
    tools:targetApi="lollipop">
    <target
        android:animation="@animator/anim_search"
        android:name="search"/>

</animated-vector>

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.yrc.part7.MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/app_name" />

    <ImageView
        android:id="@+id/iv"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        app:srcCompat="@drawable/search_sys"/>


</LinearLayout>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值