标签:android style http io os 使用 ar java 文件
public class MainActivity extends Activity {
        TestOnDraw view;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                
                view = (TestOnDraw) findViewById(R.id.test);
                
                new Thread(new Runnable() {
                        
                        @Override
                        public void run() {
                                view.test();
                        }
                }).start();
        }
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <com.example.testdraw.TestOnDraw android:id="@+id/test" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
public class TestOnDraw extends View {
        public TestOnDraw(Context context) {
                this(context, null);
        }
        
        public TestOnDraw(Context context, AttributeSet attrs) {
                this(context, attrs, 0);
        }
        
        public TestOnDraw(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
        }
        @Override
        protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);
        
                Log.d("test", "in");
        }
        
        public void test() {
                postInvalidate();
        }
}
我觉得在view = (TestOnDraw) findViewById(R.id.test)时onDraw并不是延迟执行了,而是根本就没有执行。
执行了,我说清空test方法就是将test方法弄成空实现,里面一行代码都没有,完后可以看到onDraw还是调用了的
标签:android style http io os 使用 ar java 文件
原文地址:http://www.cnblogs.com/lianxu61/p/4002131.html