80,471
社区成员




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();
}
}