package wld.bawei.com.myonemoni2.view; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; /** * Created by 大金鑫 on 2017/12/3. */ public class Liushibuju extends ViewGroup { public Liushibuju(Context context) { this(context,null); } public Liushibuju(Context context, AttributeSet attrs) { this(context, attrs,0); } public Liushibuju(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); } @Override protected void onLayout(boolean b, int i, int i1, int i2, int i3) { int width=0; int height=0; int childCount = getChildCount(); for(int k=0;k<childCount;k++){ View childAt = getChildAt(k); int measuredWidth = childAt.getMeasuredWidth(); int measuredHeight = childAt.getMeasuredHeight(); childAt.layout(width,height,measuredWidth+width,measuredHeight+height); width+=measuredWidth; height+=measuredHeight; } } }
继承ViewGroup
最新推荐文章于 2024-05-06 18:47:59 发布