标签:android style http io ar os 使用 java sp
============问题描述============
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();
}
}
============解决方案1============
============解决方案2============
============解决方案3============
我觉得在view = (TestOnDraw) findViewById(R.id.test)时onDraw并不是延迟执行了,而是根本就没有执行。
执行了,我说清空test方法就是将test方法弄成空实现,里面一行代码都没有,完后可以看到onDraw还是调用了的
标签:android style http io ar os 使用 java sp
原文地址:http://www.cnblogs.com/llj1985522/p/4089496.html