当子View的内容超出其layout的位置时,是否会被栽剪掉超出的部分。
即子View的内容能否显示在其layout的外部。
源码跟踪:
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);
}
}
public class View implements Drawable.Callback, KeyEvent.Callback,
AccessibilityEventSource {
...
final RenderNode mRenderNode;
....
}
public boolean setClipToBounds(boolean clipToBounds) {
return nSetClipToBounds(mNativeRenderNode, clipToBounds);//目前至JNI层
}
工具类:
public static void disableParentsClip(@NonNull View view) {
while (view.getParent() != null && view.getParent() instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view.getParent();
viewGroup.setClipChildren(false);
viewGroup.setClipToPadding(false);
view = viewGroup;
}
}
public static void enableParentsClip(@NonNull View view) {
while (view.getParent() != null && view.getParent() instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view.getParent();
viewGroup.setClipChildren(true);
viewGroup.setClipToPadding(true);
view = viewGroup;
}
}
来源 Smoke & Mirrors: The Magic Behind Wonderful UI in Android