android重写view和viewgroup的区别

重写view:

  View类一般用于绘图操作,重写它的onDraw方法,但它不可以包含其他组件,没有addView(View view)方法。

重写viewgroup:

     ViewGroup是一个组件容器,它可以包含任何组件,但必须重写onLayout(boolean changed,int l,int t,int r,int b)和onMesure(int widthMesureSpec,int heightMesureSpec)方法. 否则ViewGroup中添加组件是不会显示的。

自定义重写LinearLayout:

   貌似不需要重写onLayout方法了,因为LinearLayout本身就是继承自ViewGroup  但是构造函数会出现需要添加 @SuppressLint("NewApi")  的情况

-----待续完善

原文地址:https://www.cnblogs.com/feijian/p/4299639.html