gpt4 book ai didi

Android - 单击列表项时滑动 fragment

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

我正在尝试实现从 fragment1 过渡到 fragment2 的滑动动画,例如 this image .

首先,我尝试使用 set 和 translate 来实现 xml,但是我得到了 RuntimeException “Unknown animator name translate”。

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:fromXDelta="0%p"
android:toXDelta="-100%p"
android:duration="500">
</translate>
</set>

其次,我尝试通过使用扩展框架布局的类来解决问题,并添加“getXFraction”和“setXFraction”方法,例如this post

public class SlidingFrameLayout extends FrameLayout
{
private static final String TAG = SlidingFrameLayout.class.getName();
public SlidingFrameLayout(Context context) {
super(context);
}

public SlidingFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

public float getXFraction()
{
final int width = getWidth();
if(width != 0) return getX() / getWidth();
else return getX();
}

public void setXFraction(float xFraction) {
final int width = getWidth();
setX((width > 0) ? (xFraction * width) : -9999);
}

public float getYFraction()
{
final int height = getHeight();
if(height != 0) return getY() / getHeight(); else return getY();
}

public void setYFraction(float yFraction) {
final int height = getHeight();
setY((height > 0) ? (yFraction * height) : -9999);
}
}

但是我还是不知道SlidingFrameLayout应该怎么用?请帮我。 T___T

最佳答案

您需要使用 objectAnimator 而不是 translate。这是一些带有示例的帖子:Animate the transition between fragmentsAndroid Fragments and animation

关于Android - 单击列表项时滑动 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17810870/

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