您的位置:首页 > 移动开发 > Android开发

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

2017-08-03 11:36 381 查看
一、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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  动画