android - 使用动画时 Trespass ViewGroup 的 Limits

标签 android android-layout android-animation android-viewgroup

我在 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/

相关文章:

Android SQLite 事务回滚工具?

android - 在android中添加水印图片

android - 如何判断ListView的滚动方向

android - 从服务器返回响应时完成 Activity ,但等待动画结束

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

Android Studio Gradle 选项卡

android - 从 Android 应用程序以编程方式调用 Google Now 搜索

java - 如何仅将属性设置为 android 的搜索栏缩略图?

android - 更改 ImageButton 的 ImageBitmap 的动画

java - 如何在android中放大位图的触摸点?