android:仅为一个孩子申请clipChildren

时间:2015-05-21 04:25:14

标签: android android-layout android-animation android-view

<RelativeLayout
                android:id="@+id/RelativeLayout_grand_parent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
                <ListView
                    android:id="@+id/ListView_grand_parent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />
            </RelativeLayout>
////////////////////////////

ListView holds the below row layout. 

/////// row_layout.xml ///////
<RelativeLayout
                android:id="@+id/RelativeLayout_parent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
                <ImageView
                    android:id="@+id/ImageView_child"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/heart_icon" />
            </RelativeLayout>
////////////////////////////

I need to animate the child "ImageView_child" and move it outside the parent,
than I used below method :

disableClipOnParents(ImageView_child);
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());
    }
}

它运行良好,同时动画 ImageView_child 它不再被它的父母剪裁。但滚动列表时, ListView_grand_parent 也会出现在 RelativeLayout_grand_parent 和操作栏上。

我的要求是:

  • ImageView_child 不应被 ListView_grand_parent RelativeLayout_grand_parent 裁剪。
  • ListView_grand_parent 应该被 RelativeLayout_grand_parent 裁剪。

是否可以仅为一个孩子禁用剪辑?

0 个答案:

没有答案