Android5.0以上共享元素动画及水波纹动画快速配置

一、Android5.0以上版本的共享元素的配置。
1、在格式配置文件中配置style属性。

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="TransitionTheme" parent="AppTheme">
        <item name="android:windowContentTransitions">true</item>
    </style>

2、在manifest配置文件中给Activity配置所使用到的主题。

        <activity
            android:name=".ActivityTest1"
            android:theme="@style/TransitionTheme">
            <intent-filter>
                <action android:name="com.huaxinzhi.testnewanimation.intent.action.ActivityTest1" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

3、多个界面的共享元素的名称要统一,并进行配置。

android:transitionName="shareElement"

4、在界面完成跳转的过程中配置共享元素的相关属性并开始进行界面的跳转。

                Intent intent = new Intent(ActivityTest1.this , AcitivityTest1Detail.class);
                Bundle options = ActivityOptionsCompat.makeSceneTransitionAnimation(ActivityTest1.this,view,"shareElement").toBundle();
                ActivityCompat.startActivity(ActivityTest1.this,intent,options);

二、水波纹效果之–触摸反馈
1、编辑rippleDrawable配置文件,在drawable目录下。

<ripple
    android:color="@color/red"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="@color/black"/>
        </shape>
    </item>
</ripple>

2、在布局文件xml文件中使用该属性。

                <Button
                    android:background="@drawable/ripple_drawable"
                    android:id="@+id/circle_one"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent"
                    android:textColor="@android:color/white"
                    android:text="有边界"/>
                <Button
                    android:background="?Android:attr/selectableItemBackground"
                    android:id="@+id/circle_one"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent"
                    android:textColor="@android:color/white"
                    android:text="有边界"/>
                <Button
                    android:background="?android:attr/selectableItemBackgroundBorderless"
                    android:colorControlHighlight="@color/red"
                    android:id="@+id/circle_two"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:textColor="@android:color/white"
                    android:text="无边界"/>

三、水波纹–Reveal effect(揭示效果)

                Animator animator;
                if (repeat){
                    animator = ViewAnimationUtils
                            .createCircularReveal(v,v.getWidth()/2,v.getHeight()/2,v.getWidth(),0);
                }else {
                    animator = ViewAnimationUtils
                            .createCircularReveal(v,v.getWidth()/2,v.getHeight()/2,0,v.getWidth());
                }
                repeat = !repeat;
                animator.setInterpolator(new DecelerateInterpolator());
                animator.setDuration(1500);
                animator.start();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值