新活动通知显示过渡 [英] Circular reveal transition for new activity

查看:171
本文介绍了新活动通知显示过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按<一个href="https://developer.android.com/training/material/animations.html">https://developer.android.com/training/material/animations.html

  

ViewAnimationUtils.createCircularReveal()方法可以   动画剪辑圆圈来显示或隐藏的景色。

     

要利用这种效应露出了previously看不见的观点:

  // previously无形的看法
查看MyView的= findViewById(R.id.my_view);

//获取中心裁剪圈
INT CX =(myView.getLeft()+ myView.getRight())/ 2;
INT CY =(myView.getTop()+ myView.getBottom())/ 2;

//获取裁剪圆最后半径
INT finalRadius = Math.max(myView.getWidth(),myView.getHeight());

//创建动画此视图(起始半径为零)
动画动画=
    ViewAnimationUtils.createCircularReveal(MyView的,CX,CY,0,finalRadius);

//使视图中显示,并启动动画
myView.setVisibility(View.VISIBLE);
anim.start();
 

这是为了揭示一个观点。我如何使用它来循环揭示整个活动中,没有任何共享的元素?

具体而言,我想我searchActivity成圆从工具栏的搜索操作按钮显示。

解决方案

寻找没有结果半天的解决方案后,我想出了一个自己的实现。我使用的是具有匹配根布局透明的活动。 根布局是一个视图,然后可以用 createCircularReveal透露()

我的code是这样的:

在styles.xml主题定义

 &LT;样式名称=Theme.Transparent父=Theme.AppCompat.Light.NoActionBar&GT;
    &LT;项目名称=机器人:windowIsTranslucent&GT;真&LT; /项目&GT;
    &LT;项目名称=机器人:statusBarColor&GT; @android:彩色/透明&LT; /项目&GT;
    &LT;项目名称=机器人:windowBackground&GT; @android:彩色/透明&LT; /项目&GT;
&LT; /风格&GT;
 

在AndroidManifest.xml中活动定义

 &LT;活动
        机器人:名称=。ui.CircularRevealActivity
        机器人:主题=@风格/ Theme.Transparent
        机器人:launchMode =singleTask
        /&GT;
 

然后,我宣布我的活动布局(我选择DrawerLayout,才能够得出下方的状态栏,每个布局应该在这里工作。)

 &LT; android.support.v4.widget.DrawerLayout
    机器人:ID =@ + ID / drawer_layout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    &GT;

    &LT;的FrameLayout
        机器人:ID =@ + ID / root_layout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:背景=@色/ honey_melon
        &GT;

        &LT;! - 在此处插入您的实际布局 - &GT;

    &LT; /的FrameLayout&GT;

&LT; /android.support.v4.widget.DrawerLayout>
 

重要的是ID为的的FrameLayout root_layout 。这种观点将被揭示的活动。

最后,我实现了 CircularRevealActivity 和重写的onCreate()

  @覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.do_not_move,R.anim.do_not_move);

    的setContentView(R.layout.activity_reveal_circular);

    如果(savedInstanceState == NULL){
        rootLayout.setVisibility(View.INVISIBLE);

        ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver();
        如果(viewTreeObserver.isAlive()){
            viewTreeObserver.addOnGlobalLayoutListener(新ViewTreeObserver.OnGlobalLayoutListener(){
                @覆盖
                公共无效onGlobalLayout(){
                    circularRevealActivity();
                }
            });
        }
    }
}
 

重要的是把 circularRevealActivity() OnGlobalLayoutListener ,因为视图需要绘制的动画。

circularRevealActivity()看起来像ISHAAN的建议:

 私人无效circularRevealActivity(){

    INT CX = rootLayout.getWidth()/ 2;
    INT CY = rootLayout.getHeight()/ 2;

    浮finalRadius = Math.max(rootLayout.getWidth(),rootLayout.getHeight());

    //创建动画此视图(起始半径为零)
    动画circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout,CX,CY,0,finalRadius);
    circularReveal.setDuration(1000);

    //使视图中显示,并启动动画
    rootLayout.setVisibility(View.VISIBLE);
    circularReveal.start();
}
 

修改1

R.anim.do_not_move 的定义中添加。但是,它应该不会是太行,如果你的设计没有指定默认过渡的活动。让我知道

R.anim.do_not_move:

 &LT;设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android&GT;
&LT;翻译
    机器人:fromYDelta =0
    机器人:toYDelta =0
    机器人:时间=@安卓整数/ config_mediumAnimTime
    /&GT;
&LT; /集&gt;
 

As per https://developer.android.com/training/material/animations.html

The ViewAnimationUtils.createCircularReveal() method enables you to animate a clipping circle to reveal or hide a view.

To reveal a previously invisible view using this effect:

// previously invisible view
View myView = findViewById(R.id.my_view);

// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;

// get the final radius for the clipping circle
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());

// create the animator for this view (the start radius is zero)
Animator anim =
    ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);

// make the view visible and start the animation
myView.setVisibility(View.VISIBLE);
anim.start();

This is meant to reveal a view. How can I use this to circularly reveal an entire activity, without any shared elements?

Specifically, I'd like my searchActivity to circularly reveal from the search action button in the toolbar.

解决方案

After looking for a solution for half a day without a result, I came up with an own implementation. I'm using a transparent activity with a matching root layout. The root layout is a view which can then be revealed with createCircularReveal().

My code looks like this:

Theme Definition in styles.xml

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

Activity Definition in AndroidManifest.xml

<activity
        android:name=".ui.CircularRevealActivity"
        android:theme="@style/Theme.Transparent"
        android:launchMode="singleTask"
        />

then I declared a layout for my activity (I've chosen DrawerLayout, to be able to draw below the status bar. Every layout should work here.)

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <FrameLayout
        android:id="@+id/root_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/honey_melon"
        >

        <!-- Insert your actual layout here -->

    </FrameLayout>

</android.support.v4.widget.DrawerLayout>

Important is the FrameLayout with the id root_layout. This view will be revealed in the activity.

Finally I implemented CircularRevealActivity and overwrote onCreate():

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.do_not_move, R.anim.do_not_move);

    setContentView(R.layout.activity_reveal_circular);

    if (savedInstanceState == null) {
        rootLayout.setVisibility(View.INVISIBLE);

        ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    circularRevealActivity();
                }
            });
        }
    }
}

It was important to put circularRevealActivity() into a OnGlobalLayoutListener, because the view needs to be drawn for the animation.

circularRevealActivity() looks like Ishaan's proposal:

private void circularRevealActivity() {

    int cx = rootLayout.getWidth() / 2;
    int cy = rootLayout.getHeight() / 2;

    float finalRadius = Math.max(rootLayout.getWidth(), rootLayout.getHeight());

    // create the animator for this view (the start radius is zero)
    Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, cx, cy, 0, finalRadius);
    circularReveal.setDuration(1000);

    // make the view visible and start the animation
    rootLayout.setVisibility(View.VISIBLE);
    circularReveal.start();
}

Edit 1

The definition for R.anim.do_not_move was added. However, it should work without that line too, if your design does not specify default transitions for activities. Let me know

R.anim.do_not_move:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
    android:fromYDelta="0"
    android:toYDelta="0"
    android:duration="@android:integer/config_mediumAnimTime"
    />
</set>

这篇关于新活动通知显示过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆