gpt4 book ai didi

android - Activity 和共享 View 之间的动画 : glitchy/hack at the ends of animation?

转载 作者:IT王子 更新时间:2023-10-28 23:32:07 25 4
gpt4 key购买 nike

所以,我面临的问题是我在两个 Activity 和两个共享 View 之间做的动画看起来不太好。

问题在于它的“故障”,当从 Activity2 回到 Activity1 时,共享的 TextViews 在动画结束时会闪烁,显示来自 Activity2 的“更大的文本”只有几分之一秒,所以它“闪烁”。

Activity 1(RecyclerView 有三个项目):

enter image description here

Activity 二(详情):

enter image description here

我在制作动画的同时拍摄了屏幕。当从 Activity2 回到 Activit2 时,您可以看到文本在最后闪烁。这段视频(36MB,大小抱歉)展示了它:

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

问题是:我做错了什么?为什么会这样闪烁?我看过其他动画的视频,它们都非常流畅和漂亮。

我已经测试了不同类型的转换(changeBounds、explode 等),但总会发生一些奇怪的事情。任何提示,想法将不胜感激 =)

我的代码

主 Activity (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( Activity 2):

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);
}
}

还有布局,首先是 RecyclerView 列表中的 my_text_view:

<?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>

还有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>

还有过渡xml(在/res/transition中):

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

还有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>

最佳答案

问题是您正在尝试使用 ChangeBounds 转换将 TextView 的大小设置为共享元素。由于 ChangeBounds 的工作方式,这将不起作用。 ChangeBounds 过渡在过渡的开始和结束处分析 View 的布局边界,并在两者之间设置动画。 ChangeBounds 适用于任意 View ,因此在转换期间它不会在您的 TextView 上调用 setTextSize() ......这是你的东西如果您想在动画期间看到 TextView 的大小无缝增加/减小,则需要使用自定义转换。 this StackOverflow answer 中有一些关于如何做到这一点的信息。 .

关于android - Activity 和共享 View 之间的动画 : glitchy/hack at the ends of animation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27123561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com