android–clipChildren无法正常工作

android–clipChildren无法正常工作,第1张

概述在我的应用程序中,我试图使用动画移动图像.当我尝试将图像(imageView2或imageView4)设置为imageView1时,图像在移出布局时会切割.源图像是imageView2或imageView4,目标图像是imageView1下面是我的XML:<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="ht

在我的应用程序中,我试图使用动画移动图像.
当我尝试将图像(imageVIEw2或imageVIEw4)设置为imageVIEw1时,图像在移出布局时会切割.
源图像是imageVIEw2或imageVIEw4,目标图像是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的父母之一可能是剪辑子项(有时兼容性库添加一个神秘的VIEwGroup,例如NoSaveStateFrameLayout).我过去曾经使用过类似的东西来成功禁用视图的所有父级的剪辑:

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());    }}
总结

以上是内存溢出为你收集整理的android – clipChildren无法正常工作全部内容,希望文章能够帮你解决android – clipChildren无法正常工作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1097615.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存