clipChildren无法正常工作 [英] clipChildren is not working

查看:112
本文介绍了clipChildren无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我尝试使用动画移动图像。
当我尝试将图像动画( imageView2 imageView4 )动画为 imageView1 ,当图像从布局中移出时,图像将被剪切。
此处,源图像为 imageView2 imageView4 ,目标图像为 imageView1

In my application i am trying to move images using animation. When i try to animate the image (imageView2 or imageView4) to imageView1, the image is cutting when it is moving out of the Layout. Here Source image is imageView2 or imageView4 and destination image is imageView1

下面是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/animRL"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="40dp"
        android:layout_height="60dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/deskcard" />

    <RelativeLayout
        android:id="@+id/baselayout"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/imageView1"
        android:clipChildren="false"
        android:clipToPadding="false" >

        <RelativeLayout
            android:id="@+id/layout"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:gravity="bottom|center" >

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignTop="@+id/imageView4"
                android:layout_marginLeft="118dp"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:src="@drawable/test" />

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="40dp"
                android:layout_height="60dp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="16dp"
                android:layout_marginRight="104dp"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:src="@drawable/test1" />
        </RelativeLayout>
    </RelativeLayout>


</RelativeLayout>

动画代码如下:

imageView4.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                     int sourceCoords[] = new int[2];
                        int targetCoords[] = new int[2];
                        int xDelta;
                        int yDelta;
                        imageView4.getLocationOnScreen(sourceCoords);
                        image.getLocationOnScreen(targetCoords);
                        xDelta = targetCoords[0] - sourceCoords[0];
                        yDelta = targetCoords[1] - sourceCoords[1];

                    TranslateAnimation animation = new TranslateAnimation(0, xDelta, 0, yDelta);
                    animation.setDuration(400);
                    animation.setFillAfter(false);
                    animation.setAnimationListener(new MyAnimationListener());

                    imageView4.startAnimation(animation);
                }
            });


推荐答案

您的RelativeLayout的父母之一可能正在修剪孩子(有时兼容性库会添加一个诸如 NoSaveStateFrameLayout 之类的神秘ViewGroup。例)。我过去曾成功使用过类似的方法来禁用视图的所有父视图上的剪辑:

One of the parents of your RelativeLayout might be clipping children (sometimes compatibility libraries add a mystery ViewGroup such as NoSaveStateFrameLayout for example). I've used something like this in the past with success to disable clip on all parents of a view:

public void disableClipOnParents(View v) {
    if (v.getParent() == null) {
        return;
    }

    if (v instanceof ViewGroup) {
        ((ViewGroup) v).setClipChildren(false);
    }

    if (v.getParent() instanceof View) {
        disableClipOnParents((View) v.getParent());
    }
}

这篇关于clipChildren无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆