Android -- setWillNotDraw()_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > Android -- setWillNotDraw()

Android -- setWillNotDraw()

 2014/12/28 17:01:30  我爱物联网  程序员俱乐部  我要评论(0)
  • 摘要:干货处理onDraw()方法不被执行的解决方法:setWillNotDraw(false);官方文档的解释:Ifthisviewdoesn'tdoanydrawingonitsown,setthisflagtoallowfurtheroptimizations.Bydefault,thisflagisnotsetonView,butcouldbesetonsomeViewsubclassessuchasViewGroup.Typically,ifyouoverrideonDraw(Canvas
  • 标签:android not

干货                                                                                   

处理onDraw()方法不被执行的解决方法

setWillNotDraw(false);

官方文档的解释:

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.

用法                                                                                   

public class LayoutLayout extends LinearLayout {  
  
        public LayoutLayout (Context context, intposition) {  
                super(context);  
                setWillNotDraw(false);  
        }  
  
        @Override  
        protected void onDraw(Canvas canvas) {   
                super.onDraw(canvas);  
                }  
        }  
}

总结                                                                                   

设置view是否更改,如果用自定义的view,重写ondraw()应该将调用此方法设置为false,这样程序会调用自定义的布局。

我是天王盖地虎的分割线                                                             

发表评论
用户名: 匿名