为什么cardview 的cilpchildren无效?

请问一下如何查看xml中的属性在java代码中被引用的位置?

<!--cradview -->
<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:clipChildren="false"
    app:cardBackgroundColor="@color/actionsheet_gray">

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginTop="-20dp"
        android:background="@mipmap/ic_launcher"/>

</android.support.v7.widget.CardView>
<!--linearlayout,framelayout, relativelayout等 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:background="@color/actionsheet_gray"
    android:orientation="vertical"
    >

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginTop="-20dp"
        android:background="@mipmap/ic_launcher"/>

</LinearLayout>

图片描述

哦我现在在ViewGroup找到了使用的地方initFromAttributes

private void initFromAttributes(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewGroup, defStyleAttr,
            defStyleRes);

    final int N = a.getIndexCount();
    for (int i = 0; i < N; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
            case R.styleable.ViewGroup_clipChildren:
                setClipChildren(a.getBoolean(attr, true));
                break;
            case R.styleable.ViewGroup_clipToPadding:
                setClipToPadding(a.getBoolean(attr, true));
                break;
                
                //...

对这个属性有影响的内容

public void setClipChildren(boolean clipChildren) {
    boolean previousValue = (mGroupFlags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN;
    if (clipChildren != previousValue) {
        setBooleanFlag(FLAG_CLIP_CHILDREN, clipChildren);
        for (int i = 0; i < mChildrenCount; ++i) {
            View child = getChildAt(i);
            if (child.mRenderNode != null) {
                child.mRenderNode.setClipToBounds(clipChildren);
            }
        }
        invalidate(true);
    }
}
阅读 4.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题