加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Android 自定义view 不执行 ondraw的解决措施

发布时间:2021-11-25 17:14:05 所属栏目:PHP教程 来源:互联网
导读:Android 自定义view 不执行 ondraw的解决办法 public class BackgroundLayout extends LinearLayout { public BackgroundLayout(Context context, int position) { super(context); span style=color:#ff0000; setWillNotDraw/span(false); } @Override prot

Android 自定义view 不执行 ondraw的解决办法
 
public class BackgroundLayout extends LinearLayout {  
  
              public BackgroundLayout(Context context, int position) {  
                      super(context);  
                    <span style="color:#ff0000;">  setWillNotDraw</span>(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.

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读