下面列出了android.view.ViewGroup#setClipChildren ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.game_fragment, container, false);
view.setClipChildren(false);
((ViewGroup)view.findViewById(R.id.game_board)).setClipChildren(false);
mTime = (TextView) view.findViewById(R.id.time_bar_text);
mTimeImage = (ImageView) view.findViewById(R.id.time_bar_image);
FontLoader.setTypeface(Shared.context, new TextView[] {mTime}, Font.GROBOLD);
mBoardView = BoardView.fromXml(getActivity().getApplicationContext(), view);
FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.game_container);
frameLayout.addView(mBoardView);
frameLayout.setClipChildren(false);
// build board
buildBoard();
Shared.eventBus.listen(FlipDownCardsEvent.TYPE, this);
Shared.eventBus.listen(HidePairCardsEvent.TYPE, this);
Shared.eventBus.listen(GameWonEvent.TYPE, this);
return view;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.game_fragment, container, false);
view.setClipChildren(false);
((ViewGroup)view.findViewById(R.id.game_board)).setClipChildren(false);
mTime = (TextView) view.findViewById(R.id.time_bar_text);
mTimeImage = (ImageView) view.findViewById(R.id.time_bar_image);
FontLoader.setTypeface(Shared.context, new TextView[] {mTime}, Font.GROBOLD);
mBoardView = BoardView.fromXml(getActivity().getApplicationContext(), view);
FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.game_container);
frameLayout.addView(mBoardView);
frameLayout.setClipChildren(false);
// build board
buildBoard();
Shared.eventBus.listen(FlipDownCardsEvent.TYPE, this);
Shared.eventBus.listen(HidePairCardsEvent.TYPE, this);
Shared.eventBus.listen(GameWonEvent.TYPE, this);
return view;
}
/**
* 设置是否限制子 View 在其边界内绘制
* @param viewGroup {@link ViewGroup}
* @param clipChildren {@code true} yes, {@code false} no
* @return {@code true} success, {@code false} fail
*/
public static boolean setClipChildren(final ViewGroup viewGroup, final boolean clipChildren) {
if (viewGroup != null) {
viewGroup.setClipChildren(clipChildren);
return true;
}
return false;
}
@Override
public TabAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
TabView view = (TabView)LayoutInflater.from(parent.getContext()).inflate(R.layout.tab_view, parent, false);
parent.setClipToPadding(false);
parent.setClipChildren(false);
return new MyViewHolder(view);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
parent.setClipChildren(false);
parent.setClipToPadding(false);
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.item_conversation, null);
convertView.setTag(new ViewHolder(convertView));
}
initializeViews(getItem(position), (ViewHolder) convertView.getTag());
return convertView;
}
/**
* 手动添加,不在XML添加的话.
*/
public void attach2Window(Activity activity)
{
ViewGroup rootView = (ViewGroup)activity.findViewById(Window.ID_ANDROID_CONTENT);
ViewGroup.LayoutParams layoutParams =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
rootView.addView(this, layoutParams);
rootView.setClipChildren(false);
rootView.setClipToPadding(false);
}
private void clipViewToPaddingForBadge(boolean flag) {
// Avoid clipping a badge if it's displayed.
// Clip children / view to padding when no badge is displayed.
setClipChildren(flag);
setClipToPadding(flag);
ViewGroup parent = (ViewGroup) getParent();
if (parent != null) {
parent.setClipChildren(flag);
parent.setClipToPadding(flag);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (getParent() != null) {
ViewGroup v = (ViewGroup) getParent();
v.setClipChildren(false);
}
}
private static List<Boolean> setAncestralClipping(
@NonNull View view, boolean clipChildren, List<Boolean> was) {
if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
was.add(group.getClipChildren());
group.setClipChildren(clipChildren);
}
ViewParent parent = view.getParent();
if (parent != null && parent instanceof ViewGroup) {
setAncestralClipping((ViewGroup) parent, clipChildren, was);
}
return was;
}
public static void restoreAncestralClipping(@NonNull View view, List<Boolean> was) {
if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
group.setClipChildren(was.remove(0));
}
ViewParent parent = view.getParent();
if (parent != null && parent instanceof ViewGroup) {
restoreAncestralClipping((ViewGroup) parent, was);
}
}
/**
* 手动添加,不在XML添加的话.
*/
public void attach2Window(Activity activity) {
ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
rootView.addView(this, layoutParams);
rootView.setClipChildren(false);
rootView.setClipToPadding(false);
}
/**
* 手动添加,不在XML添加的话.
*/
public void attach2Window(Activity activity) {
ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
rootView.addView(this, layoutParams);
rootView.setClipChildren(false);
rootView.setClipToPadding(false);
}
private void setup() {
setupBackZone();
setupSafeZone();
setupThumbZone();
setupDrawableBounds();
if (this.getMeasuredWidth() > 0 && this.getMeasuredHeight() > 0) {
mSaveLayerZone = new RectF(0, 0, this.getMeasuredWidth(), this.getMeasuredHeight());
}
ViewGroup parent = (ViewGroup) this.getParent();
if (parent != null) {
parent.setClipChildren(false);
}
}
/**
* Clear the animation garbage of the target view.
*/
private static void clearClippedChildren(ViewGroup viewGroup) {
viewGroup.setClipChildren(true);
viewGroup.invalidate();
viewGroup.setClipChildren(false);
}
public TvViewBring(ViewGroup vg)
{
vg.setClipChildren(false);
vg.setClipToPadding(false);
}
private void addTile(final int id, ViewGroup parent) {
final TileView tileView = TileView.fromXml(getContext(), parent);
tileView.setLayoutParams(mTileLayoutParams);
parent.addView(tileView);
parent.setClipChildren(false);
mViewReference.put(id, tileView);
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
return mBoardArrangment.getTileBitmap(id, mSize);
}
@Override
protected void onPostExecute(Bitmap result) {
tileView.setTileImage(result);
}
}.execute();
tileView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!mLocked && tileView.isFlippedDown()) {
tileView.flipUp();
flippedUp.add(id);
if (flippedUp.size() == 2) {
mLocked = true;
}
Shared.eventBus.notify(new FlipCardEvent(id));
}
}
});
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(tileView, "scaleX", 0.8f, 1f);
scaleXAnimator.setInterpolator(new BounceInterpolator());
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(tileView, "scaleY", 0.8f, 1f);
scaleYAnimator.setInterpolator(new BounceInterpolator());
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(scaleXAnimator, scaleYAnimator);
animatorSet.setDuration(500);
tileView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
animatorSet.start();
}
public WidgetTvViewBring(ViewGroup vg) {
vg.setClipChildren(false);
vg.setClipToPadding(false);
// vg.setChildrenDrawingOrderEnabled(true);
}
public WidgetTvViewBring(ViewGroup vg) {
vg.setClipChildren(false);
vg.setClipToPadding(false);
// vg.setChildrenDrawingOrderEnabled(true);
}
private void addTile(final int id, ViewGroup parent) {
final TileView tileView = TileView.fromXml(getContext(), parent);
tileView.setLayoutParams(mTileLayoutParams);
parent.addView(tileView);
parent.setClipChildren(false);
mViewReference.put(id, tileView);
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
return mBoardArrangment.getTileBitmap(id, mSize);
}
@Override
protected void onPostExecute(Bitmap result) {
tileView.setTileImage(result);
}
}.execute();
tileView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mLocked && tileView.isFlippedDown()) {
tileView.flipUp();
flippedUp.add(id);
if (flippedUp.size() == 2) {
mLocked = true;
}
Shared.eventBus.notify(new FlipCardEvent(id));
}
}
});
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(tileView, "scaleX", 0.8f, 1f);
scaleXAnimator.setInterpolator(new BounceInterpolator());
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(tileView, "scaleY", 0.8f, 1f);
scaleYAnimator.setInterpolator(new BounceInterpolator());
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(scaleXAnimator, scaleYAnimator);
animatorSet.setDuration(500);
tileView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
animatorSet.start();
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
View view = View.inflate(context, R.layout.record_view_layout, null);
addView(view);
ViewGroup viewGroup = (ViewGroup) view.getParent();
viewGroup.setClipChildren(false);
arrow = view.findViewById(R.id.arrow);
slideToCancel = view.findViewById(R.id.slide_to_cancel);
smallBlinkingMic = view.findViewById(R.id.glowing_mic);
counterTime = view.findViewById(R.id.counter_tv);
basketImg = view.findViewById(R.id.basket_img);
slideToCancelLayout = view.findViewById(R.id.shimmer_layout);
hideViews(true);
if (attrs != null && defStyleAttr == -1 && defStyleRes == -1) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RecordView,
defStyleAttr, defStyleRes);
int slideArrowResource = typedArray.getResourceId(R.styleable.RecordView_slide_to_cancel_arrow, -1);
String slideToCancelText = typedArray.getString(R.styleable.RecordView_slide_to_cancel_text);
int slideMarginRight = (int) typedArray.getDimension(R.styleable.RecordView_slide_to_cancel_margin_right, 30);
int counterTimeColor = typedArray.getColor(R.styleable.RecordView_counter_time_color, -1);
int arrowColor = typedArray.getColor(R.styleable.RecordView_slide_to_cancel_arrow_color, -1);
int cancelBounds = typedArray.getDimensionPixelSize(R.styleable.RecordView_slide_to_cancel_bounds, -1);
if (cancelBounds != -1)
setCancelBounds(cancelBounds, false);//don't convert it to pixels since it's already in pixels
if (slideArrowResource != -1) {
Drawable slideArrow = AppCompatResources.getDrawable(getContext(), slideArrowResource);
arrow.setImageDrawable(slideArrow);
}
if (slideToCancelText != null)
slideToCancel.setText(slideToCancelText);
if (counterTimeColor != -1)
setCounterTimeColor(counterTimeColor);
if (arrowColor != -1)
setSlideToCancelArrowColor(arrowColor);
setMarginRight(slideMarginRight, true);
typedArray.recycle();
}
animationHelper = new AnimationHelper(context, basketImg, smallBlinkingMic);
}