在Android的棒棒糖一个ListView与材料设计活动过渡动画 [英] Activity Transition animation in a ListView in Android Lollipop with Material Design

查看:344
本文介绍了在Android的棒棒糖一个ListView与材料设计活动过渡动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是主/从模式,目前移动到Android棒棒糖。我想有新的活动跃迁中的一个在我的ListView项。该动画的工作,但我不知道如何使共享的元素之间有一定的动画(在我的情况下,ImageView的)。

I am using a Master/Detail pattern and currently moving to Android Lollipop. I want to have one of the new activity transistions if I click on a item in my ListView. The animations are working but I do not know how to make a certain animation between the shared element (in my case a ImageView).

如果我在自定义的ListView(含图片和文字),点击一排,过渡应该切换到我的DetailActivtiy图像。它应该看起来像这个视频: http://youtu.be/RhiPJByIMrM?t=2m41s 或者这个视频: http://youtu.be/XkWI1FKKrs4

If I click on a row in my custom ListView (with image and text), the transition should switch to the image in my DetailActivtiy. It should look like in this video: http://youtu.be/RhiPJByIMrM?t=2m41s or this video: http://youtu.be/XkWI1FKKrs4

我已经添加了这个$​​ C $ C到我的两个ImageViews的:

I already added this code to both of my ImageViews:

<ImageView
            android:transitionName="@string/transition_title_image"/>

我的ListActivity:

My ListActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= 21) {
        //To enable window content transitions in your code instead, call the Window.requestFeature() method:
        getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS);
        Transition ts_enter = new Slide();  //Slide(); //Explode();
        Transition ts_exit = new Explode();

        ts_enter.setDuration(2000);
        ts_exit.setDuration(2000);
        /*
        If you have set an enter transition for the second activity,
        the transition is also activated when the activity starts.
        */
        getWindow().setEnterTransition(ts_enter);
        getWindow().setExitTransition(ts_exit);
    }
    super.onCreate(savedInstanceState);

使用这种方法叫我DetailActivity:

Using this method to call my DetailActivity:

    if (Build.VERSION.SDK_INT >= 21) {
        Intent intent = new Intent(ArticleListActivity.this, ArticleDetailActivity.class);
        intent.putExtra("pos", id);
        intent.putExtra("articleList", articleList);
        String transitionName = getString(R.string.transition_title_image);
        ImageView article_thumb = (ImageView) findViewById(R.id.article_thumb);

        ActivityOptionsCompat options =
                ActivityOptionsCompat.makeSceneTransitionAnimation(ArticleListActivity.this,
                        article_thumb,   // The view which starts the transition
                        transitionName    // The transitionName of the view we’re transitioning to
                );
        ActivityCompat.startActivity(ArticleListActivity.this, intent, options.toBundle());
    }

我DetailActivity:

My DetailActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= 21) {
        //To enable window content transitions in your code instead, call the Window.requestFeature() method:
        getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS);
        Transition ts_enter = new Slide();  //Slide(); //Explode();
        Transition ts_exit = new Explode();  //Slide(); //Explode();

        ts_enter.setDuration(2000);
        ts_exit.setDuration(2000);

        getWindow().setEnterTransition(ts_enter);
        getWindow().setExitTransition(ts_exit);
    }
    super.onCreate(savedInstanceState)

推荐答案

试试这个:


  1. 首先,确保你给每个的ImageView 在你的第一个活动的唯一过渡名称。如果所有的图像视图具有相同名称的过渡,该框架将不知道什么时候开始的动画和过渡将不会循规蹈矩该选哪一个。

  1. First, make sure you give each ImageView in your first activity a unique transition name. If all of the image views have the same transition name, the framework will not know which one to choose when the animation begins and the transition will not behave properly.

的ImageView 点击,通过其独特的过渡的名字到细节的活动为意图多余的。

When the ImageView is clicked, pass its unique transition name to the details activity as an Intent extra.

在细节活动的的onCreate()方法,从意图包检索名称,将其设置为的ImageView 的临时名字。

In the details activity's onCreate() method, retrieve the name from the intent bundle, and set it as the ImageView's transition name.

这篇关于在Android的棒棒糖一个ListView与材料设计活动过渡动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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