gpt4 book ai didi

Android:如何在 Activity 之间制作动画?

转载 作者:行者123 更新时间:2023-11-29 16:13:32 25 4
gpt4 key购买 nike

我对 Android 中的动画有疑问。我制作了一个包含很多产品的应用程序,您现在可以通过从左向右滑动屏幕来切换产品(转到列表中的下一个产品)但是它现在就像任何其他 Activity 一样加载。

我想要的是很多其他应用也有的东西,滑动需要让旧 Activity 向左移出屏幕,而新 Activity 同时进入屏幕。

我已经搜索和阅读了很多,但我真的不知道从哪里开始。

我的产品是 Activity ,这是它们现在的切换方式:

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// left to right swipe
if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
for(HashMap h: products) {
if (h.get("id").toString().equals(id)) {
int index = products.indexOf(h)-1;

if (index != -1) {
HashMap product = products.get(index);

dialog = ProgressDialog.show(ProductActivity.this, "",
"Laden...", true);
Intent i = new Intent(ProductActivity.this, ProductActivity.class);
i.putExtra("id", product.get("id").toString());
i.putExtra("profileId", profileId);
i.putExtra("score", product.get("score").toString());
i.putExtra("products", products);
startActivity(i);
}
else {
Toast.makeText(ProductActivity.this, "Dit is het eerste product in de lijst.", Toast.LENGTH_LONG).show();
}
}
}
}
//right to left swipe
else if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
for(HashMap h: products) {
if (h.get("id").toString().equals(id)) {
int index = products.indexOf(h)+1;

if (index != products.size()) {
HashMap product = products.get(index);

dialog = ProgressDialog.show(ProductActivity.this, "",
"Laden...", true);
Intent i = new Intent(ProductActivity.this, ProductActivity.class);
i.putExtra("id", product.get("id").toString());
i.putExtra("profileId", profileId);
i.putExtra("score", product.get("score").toString());
i.putExtra("products", products);
startActivity(i);
}
else {
Toast.makeText(ProductActivity.this, "Dit is het laatste product in de lijst.", Toast.LENGTH_LONG).show();
}
}
}
}
} catch (Exception e) {
// nothing
}
return false;
}

最佳答案

你可以试试这个 Android-Viewflow library .

ViewFlow is an Android UI widget providing a horizontally scrollable ViewGroup with items populated from an Adapter.

Viewflow with Circle indicators Viewflow with Title indicators

关于Android:如何在 Activity 之间制作动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11244106/

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