大佬教程收集整理的这篇文章主要介绍了Android:将任意变换应用于视图,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_120_9@myAnimation animation = new MyAnimation(matriX); animation.setDuration(0); animation.setFillAfter(true); view.setAnimation(animation);
有没有更好的办法?我尝试利用getChildStaticTransformation并将其放在父级中,但这样做不成功(也许我做错了?)
public class UIViewLayout extends ViewGroup { @Override protected Boolean getChildStaticTransformation(View child,Transformation t) { if(child instanceof UIViewLayout) { t.getMatrix().reset(); UIViewLayout.LayoutParams params = (UIViewLayout.LayoutParams)child.getLayoutParams(); t.setTransformationType(Transformation.TYPE_MATRIX); t.getMatrix().set(params.matriX); } return true; } public UIViewLayout(android.content.Context context) { super(context); this.setClipChildren(false); this.setCliPTOPadding(false); this.setChildrenDrawingOrderEnabled(true); this.setStaticTransformationsEnabled(true); } public UIViewLayout(Context context,AttributeSet attrs) { super(context,attrs); } public UIViewLayout(Context context,AttributeSet attrs,int defStylE) { super(context,attrs,defStylE); } @Override protected void onMeasure(int widthMeasureSpec,int heightMeasureSpeC) { int count = getChildCount(); int maxHeight = 0; int maxWidth = 0; // Find out how big everyone wants to be measureChildren(widthMeasureSpec,heightMeasureSpec); // Find rightmost and bottom-most child for (int i = 0; i < count; i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { int childRight; int childBottom; UIViewLayout.LayoutParams lp = (UIViewLayout.LayoutParams) child.getLayoutParams(); childRight = lp.x + child.getMeasuredWidth(); childBottom = lp.y + child.getMeasuredHeight(); maxWidth = Math.max(maxWidth,childRight); maxHeight = Math.max(maxHeight,childBottom); } } // Account for padding too //maxWidth += mPaddingLeft + mPaddingRight; //maxHeight += mPaddingTop + mPaddingBottom; // check against minimum height and width maxHeight = Math.max(maxHeight,getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth,getSuggestedMinimumWidth()); setMeasuredDimension(resolveSizeAndState(maxWidth,widthMeasureSpec,0),resolveSizeAndState(maxHeight,heightMeasureSpec,0)); } @Override protected ViewGroup.LayoutParams generateDefaultLayoutParams() { return new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,0); } @Override protected void onLayout(Boolean changed,int l,int t,int r,int b) { int count = getChildCount(); for (int i = 0; i < count; i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { UIViewLayout.LayoutParams lp = (UIViewLayout.LayoutParams) child.getLayoutParams(); int childLeft = lp.x; int childTop = lp.y; child.layout(childLeft,childTop,childLeft + child.getMeasuredWidth(),childTop + child.getMeasuredHeight()); } } } @Override public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { return new UIViewLayout.LayoutParams(getContext(),attrs); } // Override to allow type-checking of LayoutParams. @Override protected Boolean checkLayoutParams(ViewGroup.LayoutParams p) { return p instanceof UIViewLayout.LayoutParams; } @Override protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) { return new LayoutParams(p); } @Override public Boolean shouldDelayChildPressedState() { return false; } @Override public Boolean dispatchTouchEvent(MotionEvent ev) { for(int i = 0; i < this.getChildCount(); i++) { View child = getChildAt(i); if(child instanceof UIViewLayout) { UIViewLayout.LayoutParams params = (UIViewLayout.LayoutParams)child.getLayoutParams(); if(!params.matrix.isIdentity()) { MotionEvent ev2 = MotionEvent.obtain(ev); ev2.setLOCATIOn(ev2.getX() - params.x,ev2.getY() - params.y); Matrix m = new Matrix(); params.matrix.invert(m); ev2.transform(m); if(child.dispatchTouchEvent(ev2)) { return true; } ev2.recycle(); } } } return super.dispatchTouchEvent(ev); } public static class LayoutParams extends ViewGroup.LayoutParams { public int x; public int y; public Matrix matrix; public LayoutParams(int width,int height,int x,int y) { super(width,height); this.x = x; this.y = y; this.matrix = new Matrix(); } public LayoutParams(Context c,AttributeSet attrs) { super(c,attrs); } public LayoutParams(ViewGroup.LayoutParams sourcE) { super(sourcE); } } }
以上是大佬教程为你收集整理的Android:将任意变换应用于视图全部内容,希望文章能够帮你解决Android:将任意变换应用于视图所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。