gpt4 book ai didi

android - 如何在 android 中的网格 recyclerview 中做反向爆炸过渡动画

转载 作者:太空宇宙 更新时间:2023-11-03 10:37:16 27 4
gpt4 key购买 nike

我已经发布了使用过渡动画在 android 的网格 recyclerview 中分解内容的代码。如何实现反向爆炸,就像当我进入 ExplodeAnimationActivity 时,recyclerview 中的所有项目都应该反向爆炸。

enter image description here

public class ExplodeAnimationActivity extends AppCompatActivity {
private final String android_version_names[] = {
"Donut",
"Eclair",
"Froyo",
"Gingerbread",
"Honeycomb",
"Ice Cream Sandwich",
"Jelly Bean",
"KitKat",
"Lollipop",
"Marshmallow"
};

private final String android_image_urls[] = {
"http://api.learn2crack.com/android/images/donut.png",
"http://api.learn2crack.com/android/images/eclair.png",
"http://api.learn2crack.com/android/images/froyo.png",
"http://api.learn2crack.com/android/images/ginger.png",
"http://api.learn2crack.com/android/images/honey.png",
"http://api.learn2crack.com/android/images/icecream.png",
"http://api.learn2crack.com/android/images/jellybean.png",
"http://api.learn2crack.com/android/images/kitkat.png",
"http://api.learn2crack.com/android/images/lollipop.png",
"http://api.learn2crack.com/android/images/marshmallow.png"
};

RecyclerView recyclerView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animations);
initViews();
}

private void initViews() {
recyclerView = (RecyclerView) findViewById(R.id.card_recycler_view);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(), 2);
recyclerView.setLayoutManager(layoutManager);

ArrayList<AndroidVersion> androidVersions = prepareData();
ExplodeAnimationAdapter adapter = new ExplodeAnimationAdapter(getApplicationContext(), androidVersions);
recyclerView.setAdapter(adapter);

recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// save rect of view in screen coordinates
final Rect viewRect = new Rect();
v.getGlobalVisibleRect(viewRect);

// create Explode transition with epicenter
Transition explode = new Explode();
explode.setEpicenterCallback(new Transition.EpicenterCallback() {
@Override
public Rect onGetEpicenter(Transition transition) {
return viewRect;
}
});
explode.setDuration(1000);
TransitionManager.beginDelayedTransition(recyclerView, explode);

// remove all views from Recycler View
recyclerView.setAdapter(null);
return false;
}
});

}
private ArrayList<AndroidVersion> prepareData() {

ArrayList<AndroidVersion> android_version = new ArrayList<>();
for (int i = 0; i < android_version_names.length; i++) {
AndroidVersion androidVersion = new AndroidVersion();
androidVersion.setAndroid_version_name(android_version_names[i]);
androidVersion.setAndroid_image_url(android_image_urls[i]);
android_version.add(androidVersion);
}
return android_version;
}
}

最佳答案

迟到的答案,也许你自己找到了答案。我尝试了与您相同的示例并进行了一些更改,并且能够通过设置过渡模式来反转过渡。我还没有用回收站 View 完成它,但它也应该可以工作。

private Explode makeInExplodeTransition() {
Explode explode = new Explode();
explode.setDuration(3000);
explode.setMode(Visibility.MODE_OUT);
explode.setInterpolator(new OvershootInterpolator());
return explode;
}

如果您的转换应该被逆转,则以下更改有效:

explode.setMode(Visibility.MODE_IN);

就我而言,它看起来不起作用。我开始了这个 Activity ,直接动画和没有动画的 View 就在那里。所以我延迟开始动画。我认为问题在于动画在 Activity 完全可见之前完成,可能需要几毫秒。

关于android - 如何在 android 中的网格 recyclerview 中做反向爆炸过渡动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41479886/

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