gpt4 book ai didi

android - 使用动画时 Trespass ViewGroup 的 Limits

转载 作者:太空狗 更新时间:2023-10-29 14:12:41 24 4
gpt4 key购买 nike

我在 RelativeLayout 中有一个 ImageView。 ImageView 正在填充整个 RelativeLayout。RelativeLayout 不能变大。

我想像那样使用 ScaleAnimation 使 ImageView 更大:

final ScaleAnimation scaleAnimationGoBigger = new ScaleAnimation(1, 1.5f, 1, 1.5f,        Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);
scaleAnimationGoBigger.setDuration(1000);
scaleAnimationGoBigger.setFillAfter(true);
myImageView.startAnimation(scaleAnimationGoBigger);

RelativeLayout 的边界不允许显示整个新的更大的 ImageView,只显示适合 RelativeLayout 的部分(使其看起来像缩放效果)。

所以我的问题是:有没有办法告诉 ViewGroup 内的 View 不服从(侵入)ViewGroup 所在的边界(至少在动画期间)?

最佳答案

is there a way to tell a View inside a ViewGroup to not obey (to trespass) the ViewGroup's boundaries where it lies in ....

是的。假设您在某个 ViewGroup (viewGroupParent) 中有一个 View (myImageView)。刚刚调用了 setClipChildren(false)

    ViewGroup viewGroupParent = (ViewGroup) myImageView.getParent();
viewGroupParent.setClipChildren(false);

更多信息在这里:http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipChildren

(at least during the animation) ?

使用Animation.AnimationListener , 总的来说,它应该看起来像这样:

final ViewGroup viewGroupParent = (ViewGroup) myImageView.getParent();
viewGroupParent.setClipChildren(false);

final ScaleAnimation scaleAnimationGoBigger = new ScaleAnimation(1, 1.5f, 1, 1.5f, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);
scaleAnimationGoBigger.setDuration(1000);
scaleAnimationGoBigger.setFillAfter(true);
scaleAnimationGoBigger.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
viewGroupParent.setClipChildren(false);
}

@Override
public void onAnimationEnd(Animation animation) {
// uncomment here if you want to restore clip : viewGroupParent.setClipChildren(true);
}

@Override
public void onAnimationRepeat(Animation animation) {
// do nothing
}
});
myImageView.startAnimation(scaleAnimationGoBigger);

健康与安全!

关于android - 使用动画时 Trespass ViewGroup 的 Limits,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25666289/

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