android 自定义view 不执行 ondraw的解决办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ID19870510/article/details/6746484

</pre><p></p><pre name="code" class="java">  public class BackgroundLayout extends LinearLayout {

                public BackgroundLayout(Context context, int position) {
                        super(context);
                        setWillNotDraw(false);
                }

                @Override
                protected void onDraw(Canvas canvas) {
                       super.onDraw(canvas);
                }

        }

出现这种情况大多是继承自layout

。在构造方法中添加 setWillNotDraw 问题解决。 相关解释如下

If this view doesn't do any drawing on its own, set this flag to allow further optimizations. By default, this flag is not set on View, but could be set on some View subclasses such as ViewGroup. Typically, if you override onDraw(Canvas) you should clear this flag.


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页