在我的应用程序中,我尝试使用动画来移动图像。尽管我在每个xml块中都使用了clipChildren
false,但当我尝试对图像进行动画处理时,图像还是被剪切了
<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" >
发布于 2014-04-08 15:52:42
您的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());
}
}
发布于 2016-01-29 16:00:36
最后一个原因是"RelativeLayout“。因此,要解决这个问题,不要使用RelativeLayout作为大于父控件的父控件。改为使用FrameLayout,如下所示:
<!-- it's ok as grand parent -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false">
<!-- parent must not be a RelativeLayout -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="9dp">
<!-- Your Larger-than-parent View -->
<View
android:layout_width="56dp"
android:layout_height="138dp"
android:layout_gravity="center"
android:background="@android:color/black" />
</FrameLayout>
</RelativeLayout>
发布于 2018-12-06 23:37:57
@roflharrison的想法很好,但是代码有一些问题:这里我们递归禁用clipChildren,但是当我们到达根视图时,它的v.getParents()
将为null,该方法立即返回,并且它的ClipChildren属性不会被禁用。
更重要的是,下面这行代码:
if (v.getParent() instanceof View)
??视图的父对象不应该是ViewGroup吗?难道我们不应该禁用ViewGroup的剪辑属性,而不是View的吗?因此,我将代码更改为以下代码,并且运行得很好:
public void disableClipOnParents(View v) {
if (v == null) {
return;
}
if (v instanceof ViewGroup) {
((ViewGroup) v).setClipChildren(false);
}
disableClipOnParents((View) v.getParent());
}
https://stackoverflow.com/questions/22930626
复制相似问题