public class TextView extends ViewGroup { private int size; public TextView(Context context) { super(context); } public TextView(Context context, AttributeSet attrs) { super(context, attrs); } public TextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); measureChildren(widthMeasureSpec,heightMeasureSpec); size = MeasureSpec.getSize(widthMeasureSpec); } @Override protected void onLayout(boolean c, int l, int t, int r, int b) { int childCount = getChildCount(); int startHeight=0; int startWidth=0; for (int i=0;i<childCount;i++){ View v = getChildAt(i); v.layout(startWidth,startHeight,startWidth+v.getMeasuredWidth(),startHeight+v.getMeasuredHeight() ); startWidth+=v.getMeasuredWidth(); startHeight+=v.getMeasuredHeight(); } } }
android 自定义View 梯形布局
最新推荐文章于 2020-08-28 15:22:40 发布