Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器 软件资源

软件开发小程序制作系统集成与运维空间租用硬件开发视频监控技术咨询与支持——联系电话:0311-88999002/88999003

首页 / 操作系统 / Linux / Android 自定义view 不执行 ondraw的解决办法

Android 自定义view 不执行 ondraw的解决办法
  1. public class BackgroundLayout extends LinearLayout {  
  2.   
  3.               public BackgroundLayout(Context context, int position) {  
  4.                       super(context);  
  5.                     <span style="color:#ff0000;">  setWillNotDraw</span>(false);  
  6.   
  7.               }  
  8.   
  9.               @Override  
  10.               protected void onDraw(Canvas canvas) {  
  11.                      super.onDraw(canvas);  
  12.   
  13.               }  
  14.   
  15.       }  
出现这种情况大多是继承自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.