活动和共享视图间动画:出问题/劈在动画的两端?动画、两端、视图

2023-09-04 11:11:35 作者:谁 知道我隐藏了多少悲伤

所以,我现在面临的问题是,动漫我做的两项活动和两个共同意见是不寻找伟大。

的问题是,它的出问题,从活性2回到活性1时,所述TextViews被共享排序闪烁的在动画结束,揭示从活性2为几分之一秒的更大文本,所以它闪烁。

活动1(RecyclerView有三个项目):

活动2(详细信息):

我拍摄的画面,一边做动画。当准备从活性2回Activit2,你可以看到文本闪烁在最后。此视频(36MB,比较遗憾的大小)显示它:

https://drive.google.com/file/d/ 0B3wIZ9CS9Kj_a0MyVFlzX1YtY0E /有何看法?USP =共享

的问题是:什么,我做错了什么?为什么闪烁这样呢?我看到视频上的其他anims,而且都是超光滑美观。

我已经测试了不同类型的转变(changeBounds,爆炸,等等等等),但总是有一些奇怪的事情。任何提示,想法将不胜AP preciated =)

我的code

MainActivity(活动1):

包se.snap code.loll​​ipoptest; 进口android.app.Activity; 进口android.app.ActivityOptions; 进口android.content.Intent; 进口android.os.Bundle; 进口android.support.v4.view.GestureDetectorCompat; 进口android.support.v7.widget.DefaultItemAnimator; 进口android.support.v7.widget.LinearLayoutManager; 进口android.util.Pair; 进口android.view.GestureDetector; 进口android.view.Menu; 进口android.view.MenuItem; 进口android.support.v7.widget.RecyclerView; 进口android.view.MotionEvent; 进口android.view.View; 进口android.widget.TextView; 进口android.widget.Toast; 公共类MainActivity延伸活动{     私人RecyclerView mRecyclerView;     私人MyAdapter mAdapter;     私人RecyclerView.LayoutManager mLayoutManager;     GestureDetectorCompat gestureDetector;     @覆盖     保护无效的onCreate(包savedInstanceState){         super.onCreate(savedInstanceState);         的setContentView(R.layout.activity_main);         mRecyclerView =(RecyclerView)findViewById(R.id.my_recycler_view);         //使用此设置来提高性能,如果你知道的变化         //内容不改变RecyclerView的布局大小         mRecyclerView.setHasFixedSize(真正的);         //使用线性布局管理器         mLayoutManager =新LinearLayoutManager(本);         mRecyclerView.setLayoutManager(mLayoutManager);         //指定适配器(参见下一个示例)         的String []字符串=新的String [3];         串[0] =A1;         串[1] =A2;         串[2] =A3;         mAdapter =新MyAdapter(串);         mRecyclerView.setAdapter(mAdapter);         mAdapter.setOnItemClickListener(新OnItemClickListener(){             @覆盖             公共无效onItemClick(查看视图,INT位置){                 最后的TextView headerView =(TextView中)view.findViewById(R.id.textView1);                 最后的TextView的TextView =(TextView中)view.findViewById(R.id.textView2);                 意向意图=新的意图(MainActivity.this,DetailsActivity.class);                 intent.putExtra(头,headerView.getText()的toString());                 intent.putExtra(文本,textView.getText()的toString());                 ActivityOptions选项= ActivityOptions.makeSceneTransitionAnimation(MainActivity.this,Pair.create((查看)headerView,头),                         Pair.create((视图)的TextView,文本));                 startActivity(意向,options.toBundle());             }         });         RecyclerView.ItemDecoration itemDecoration =                 新DividerItemDecoration(这一点,DividerItemDecoration.VERTICAL_LIST);         mRecyclerView.addItemDecoration(itemDecoration);         //这是默认的;这个调用实际上只需要定制ItemAnimators         mRecyclerView.setItemAnimator(新DefaultItemAnimator());     } } Animation View Guide 动画视图指南

DetailsActivity(活性2):

包se.snap code.loll​​ipoptest; 进口android.app.Activity; 进口android.os.Bundle; 进口android.view.Menu; 进口android.view.MenuItem; 进口android.widget.TextView; 公共类DetailsActivity延伸活动{     @覆盖     保护无效的onCreate(包savedInstanceState){         super.onCreate(savedInstanceState);         的setContentView(R.layout.activity_details);         字符串标题= getIntent()getStringExtra(头)。         字符串文本= getIntent()getStringExtra(文本)。         TextView的TV1 =(TextView中)findViewById(R.id.tv_details_header);         tv1.setText(头);         TextView的TV2 =(TextView中)findViewById(R.id.tv_details_text);         tv2.setText(文本);     } }

和布局,首先my_text_view那就是在RecyclerView的清单:

< XML版本=1.0编码=UTF-8&GT?; < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android     机器人:方向=垂直机器人:layout_width =match_parent     机器人:layout_height =match_parent     机器人:可点击=真     机器人:可聚焦=真     机器人:背景=机器人:ATTR / selectableItemBackground     机器人:colorControlHighlight =@机器人:彩色/ holo_blue_light     机器人:填充=10dp>     <的TextView         机器人:layout_width =WRAP_CONTENT         机器人:layout_height =WRAP_CONTENT         机器人:textAppearance =机器人:ATTR / textAppearanceLarge         机器人:文本=我的标题IS HERE         机器人:transitionName =头         机器人:ID =@ + ID / textView1/>     <的TextView         机器人:layout_width =WRAP_CONTENT         机器人:layout_height =WRAP_CONTENT         机器人:textAppearance =机器人:ATTR / textAppearanceSmall         机器人:文本=这是一些文字,是相关性         机器人:transitionName =文本         机器人:ID =@ + ID / textView2/> < / LinearLayout中>

而activity_details.xml:

< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android     的xmlns:工具=htt​​p://schemas.android.com/tool​​s机器人:layout_width =match_parent     机器人:layout_height =match_parent机器人:以下属性来=@扪/ activity_horizo​​ntal_margin     机器人:paddingRight =@扪/ activity_horizo​​ntal_margin     机器人:paddingTop =@扪/ activity_vertical_margin     机器人:paddingBottom会=@扪/ activity_vertical_margin     机器人:方向=垂直     工具:上下文=se.snap code.loll​​ipoptest.DetailsActivity>     < TextView的机器人:ID =@ + ID / tv_details_header机器人:文本=A1的android:layout_width =WRAP_CONTENT         机器人:transitionName =头         机器人:TEXTSIZE =48dp         机器人:layout_height =WRAP_CONTENT/>     < TextView的机器人:ID =@ + ID / tv_details_text机器人:文本=不太重要的一些文字机器人:layout_width =WRAP_CONTENT         机器人:TEXTSIZE =24dp         机器人:transitionName =文本         机器人:layout_height =WRAP_CONTENT/> < / LinearLayout中>

和转换XML(中/ RES /转换):

< XML版本=1.0编码=UTF-8&GT?; < transitionSet的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>     < changeBounds />     <爆炸/> < / transitionSet>

和styles.xml

< XML版本=1.0编码=UTF-8&GT?; <资源>     <样式名称=AppTheme父=机器人:Theme.Material.Light>         <! - 使窗口的内容转换 - >         <项目名称=机器人:windowContentTransitions>真< /项目>         <! - 规定进入和退出的转换 - >         <项目名称=机器人:windowEnterTransition> @android:过渡/ slide_left< /项目>         <项目名称=机器人:windowExitTransition> @android:过渡/ slide_right< /项目>         &所述;! - 指定共享单元跃迁 - >         <项目名称=机器人:windowSharedElementEnterTransition>             @过渡/ change_image_transform< /项目>         <项目名称=机器人:windowSharedElementExitTransition>             @过渡/ change_image_transform< /项目>     < /风格> < /资源>

解决方案

现在的问题是,你正在尝试为一个共享的元素用动画一个的TextView 的大小 ChangeBounds 过渡。由于的方式 ChangeBounds 作品这是行不通的。该 ChangeBounds 过渡分析视图的布局界限在过渡的开始和结束,以及两者之间的动画。 ChangeBounds 适用于任意的意见,所以不会叫 setTextSize()的TextView 为您在过渡期间...这是你需要使用自定义的过渡做自己,如果你想看看的TextView 的大小无缝地增加了动画过程中/减少。这里是如何做到这一点的这个计算器回答。

So, the problem I am facing is that the animation I do between two Activities and two shared views is not looking great.

The problem is that its "glitchy", when going from Activity2 back to Activity1, the TextViews being shared sort of blinks at the end of the animation, revealing the "bigger text" from Activity2 for a fraction of a second, so it "blinks".

Activity 1 (RecyclerView with three items):

Activity 2 (Details):

I filmed the screen, while doing the animation. When going back from Activity2 to Activit2, you can see the text blink at the very end. This video (36MB, sorry for size) shows it:

https://drive.google.com/file/d/0B3wIZ9CS9Kj_a0MyVFlzX1YtY0E/view?usp=sharing

The question is: what I am doing wrong? Why is it blinking like that? I see videos on other anims, and they are all super smooth and nice.

I have tested different type of transitions (changeBounds, explode, etc etc), but there is always something weird going on. Any tips, ideas would be greatly appreciated =)

MY CODE

MainActivity (Activity1):

package se.snapcode.lollipoptest;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Pair;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity {

    private RecyclerView mRecyclerView;
    private MyAdapter mAdapter;
    private RecyclerView.LayoutManager mLayoutManager;
    GestureDetectorCompat gestureDetector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);

        // use this setting to improve performance if you know that changes
        // in content do not change the layout size of the RecyclerView
        mRecyclerView.setHasFixedSize(true);

        // use a linear layout manager
        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);

        // specify an adapter (see also next example)
        String[] strings = new String[3];
        strings[0] = "A1";
        strings[1] = "A2";
        strings[2] = "A3";
        mAdapter = new MyAdapter(strings);
        mRecyclerView.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                final TextView headerView = (TextView)view.findViewById(R.id.textView1);
                final TextView textView = (TextView)view.findViewById(R.id.textView2);
                Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
                intent.putExtra("header", headerView.getText().toString());
                intent.putExtra("text", textView.getText().toString());

                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, Pair.create((View)headerView, "header"),
                        Pair.create((View)textView, "text"));

                startActivity(intent, options.toBundle());
            }
        });

        RecyclerView.ItemDecoration itemDecoration =
                new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST);
        mRecyclerView.addItemDecoration(itemDecoration);

        // this is the default; this call is actually only necessary with custom ItemAnimators
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    }
}

DetailsActivity (Activity2):

package se.snapcode.lollipoptest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class DetailsActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);

        String header = getIntent().getStringExtra("header");
        String text = getIntent().getStringExtra("text");

        TextView tv1 = (TextView)findViewById(R.id.tv_details_header);
        tv1.setText(header);
        TextView tv2 = (TextView)findViewById(R.id.tv_details_text);
        tv2.setText(text);
    }
}

And the layouts, first my_text_view that is in the list of the RecyclerView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true"
    android:background="?android:attr/selectableItemBackground"
    android:colorControlHighlight="@android:color/holo_blue_light"
    android:padding="10dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="MY HEADER IS HERE"
        android:transitionName="header"
        android:id="@+id/textView1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="This is some text that is of relevance"
        android:transitionName="text"
        android:id="@+id/textView2" />
</LinearLayout>

And the activity_details.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="se.snapcode.lollipoptest.DetailsActivity">

    <TextView android:id="@+id/tv_details_header" android:text="A1" android:layout_width="wrap_content"
        android:transitionName="header"
        android:textSize="48dp"
        android:layout_height="wrap_content" />

    <TextView android:id="@+id/tv_details_text" android:text="Some text of lesser importance" android:layout_width="wrap_content"
        android:textSize="24dp"
        android:transitionName="text"
        android:layout_height="wrap_content" />

</LinearLayout>

And the transition xml (in /res/transition):

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <changeBounds/>
    <explode />
</transitionSet>

and the styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Material.Light">
        <!-- enable window content transitions -->
        <item name="android:windowContentTransitions">true</item>

        <!-- specify enter and exit transitions -->
        <item name="android:windowEnterTransition">@android:transition/slide_left</item>
        <item name="android:windowExitTransition">@android:transition/slide_right</item>

        <!-- specify shared element transitions -->
        <item name="android:windowSharedElementEnterTransition">
            @transition/change_image_transform</item>
        <item name="android:windowSharedElementExitTransition">
            @transition/change_image_transform</item>
    </style>
</resources>

解决方案

The problem is that you are trying to animate a TextView's size as a shared element using a ChangeBounds transition. This will not work because of the way ChangeBounds works. The ChangeBounds transition analyzes the layout bounds of a view at the start and end of the transition and animates between the two. ChangeBounds works for arbitrary views, so it will not call setTextSize() on your TextView during the transition for you... this is something you would need to do yourself using a custom transition if you wanted to see the TextView's size seamlessly increase/decrease during the animation. There is some information on how to do this in this StackOverflow answer.