我扩展了ImageView类(也尝试使用View,结果相同)
我需要执行自定义绘图,但它没有发生。 onDraw方法没有被调用
我该如何解决?
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.ImageView;
public class CompasView extends ImageView {
public CompasView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context,attrs,defStyle);
}
public CompasView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
Paint paint;
int direction = 0;
public CompasView(Context context) {
super(context);
init(context,null,0);
}
private void init(Context context, AttributeSet attrs, int defStyle) {
setWillNotDraw(false);
}
@Override
public void onDraw(Canvas canvas) {
int height = this.getHeight();
int width = this.getWidth();
Log.d("COMPASONDRAW","direction: "+direction + " width:"+width+ " height:"+height);
canvas.rotate(direction, width / 2, height / 2);
super.onDraw(canvas);
}
public void setDirection(int direction) {
this.direction = direction;
this.invalidate();
}
}
这是xml文件
<com.myapp.widget.CompasView
android:id="@+id/compasView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/space_between_adjacent_widgets_vertical"
android:layout_marginRight="@dimen/space_between_adjacent_widgets_horizontal"
android:src="@drawable/compas" />
方向更改日志:
07-28 17:47:54.060: D/COMPAS(25029): comaps orientation:176
07-28 17:47:54.130: D/COMPAS(25029): comaps orientation:173
07-28 17:47:54.190: D/COMPAS(25029): comaps orientation:166
07-28 17:47:54.260: D/COMPAS(25029): comaps orientation:156
07-28 17:47:54.320: D/COMPAS(25029): comaps orientation:143
07-28 17:47:54.390: D/COMPAS(25029): comaps orientation:134
07-28 17:47:54.450: D/COMPAS(25029): comaps orientation:127
07-28 17:47:54.510: D/COMPAS(25029): comaps orientation:123
07-28 17:47:54.580: D/COMPAS(25029): comaps orientation:117
07-28 17:47:54.640: D/COMPAS(25029): comaps orientation:108
07-28 17:47:54.710: D/COMPAS(25029): comaps orientation:98
07-28 17:47:54.770: D/COMPAS(25029): comaps orientation:95
07-28 17:47:54.830: D/COMPAS(25029): comaps orientation:96
07-28 17:47:54.890: D/COMPAS(25029): comaps orientation:99
07-28 17:47:54.960: D/COMPAS(25029): comaps orientation:101
07-28 17:47:55.030: D/COMPAS(25029): comaps orientation:102
07-28 17:47:55.090: D/COMPAS(25029): comaps orientation:105
07-28 17:47:55.150: D/COMPAS(25029): comaps orientation:108
07-28 17:47:55.210: D/COMPAS(25029): comaps orientation:110
07-28 17:47:55.280: D/COMPAS(25029): comaps orientation:112
07-28 17:47:55.340: D/COMPAS(25029): comaps orientation:114
07-28 17:47:55.410: D/COMPAS(25029): comaps orientation:116
07-28 17:47:55.470: D/COMPAS(25029): comaps orientation:118
07-28 17:47:55.530: D/COMPAS(25029): comaps orientation:120
07-28 17:47:55.600: D/COMPAS(25029): comaps orientation:121
07-28 17:47:55.660: D/COMPAS(25029): comaps orientation:123
07-28 17:47:55.720: D/COMPAS(25029): comaps orientation:124
07-28 17:47:55.790: D/COMPAS(25029): comaps orientation:125
07-28 17:47:55.860: D/COMPAS(25029): comaps orientation:126
07-28 17:47:55.910: D/COMPAS(25029): comaps orientation:128
07-28 17:47:55.980: D/COMPAS(25029): comaps orientation:128
07-28 17:47:56.050: D/COMPAS(25029): comaps orientation:129
07-28 17:47:56.100: D/COMPAS(25029): comaps orientation:130
07-28 17:47:56.180: D/COMPAS(25029): comaps orientation:131
07-28 17:47:56.240: D/COMPAS(25029): comaps orientation:131
07-28 17:47:56.300: D/COMPAS(25029): comaps orientation:132
07-28 17:47:56.370: D/COMPAS(25029): comaps orientation:132
07-28 17:47:56.430: D/COMPAS(25029): comaps orientation:133
07-28 17:47:56.490: D/COMPAS(25029): comaps orientation:133
07-28 17:47:56.550: D/COMPAS(25029): comaps orientation:134
07-28 17:47:56.620: D/COMPAS(25029): comaps orientation:134
07-28 17:47:56.690: D/COMPAS(25029): comaps orientation:135
07-28 17:47:56.740: D/COMPAS(25029): comaps orientation:135
07-28 17:47:56.810: D/COMPAS(25029): comaps orientation:136
07-28 17:47:56.880: D/COMPAS(25029): comaps orientation:136
07-28 17:47:56.940: D/COMPAS(25029): comaps orientation:136
07-28 17:47:57.000: D/COMPAS(25029): comaps orientation:137
07-28 17:47:57.060: D/COMPAS(25029): comaps orientation:137
07-28 17:47:57.120: D/COMPAS(25029): comaps orientation:137
07-28 17:47:57.190: D/COMPAS(25029): comaps orientation:138
07-28 17:47:57.260: D/COMPAS(25029): comaps orientation:138
07-28 17:47:57.320: D/COMPAS(25029): comaps orientation:138
07-28 17:47:57.390: D/COMPAS(25029): comaps orientation:138
07-28 17:47:57.450: D/COMPAS(25029): comaps orientation:138
07-28 17:47:57.510: D/COMPAS(25029): comaps orientation:138
07-28 17:47:57.580: D/COMPAS(25029): comaps orientation:139
07-28 17:47:57.640: D/COMPAS(25029): comaps orientation:139
07-28 17:47:57.710: D/COMPAS(25029): comaps orientation:139
07-28 17:47:57.760: D/COMPAS(25029): comaps orientation:139
07-28 17:47:57.830: D/COMPAS(25029): comaps orientation:139
07-28 17:47:57.900: D/COMPAS(25029): comaps orientation:139
07-28 17:47:57.960: D/COMPAS(25029): comaps orientation:139
登录内的日志
07-28 17:53:36.320: D/COMPASONDRAW(27007): direction: 195.0 width:105 height:105
07-28 17:53:36.390: D/COMPASONDRAW(27007): direction: 195.0 width:105 height:105
07-28 17:54:28.490: D/COMPASONDRAW(27007): direction: 108.0 width:105 height:105
07-28 17:54:28.510: D/COMPASONDRAW(27007): direction: 108.0 width:105 height:105
合并日志输出
07-28 18:00:26.990: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.050: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.060: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.110: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.120: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.170: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.200: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.250: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.250: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.310: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.320: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.370: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.380: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.440: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.440: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.490: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.490: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.560: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.560: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.620: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.630: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.690: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.710: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.750: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.750: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.820: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.820: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.880: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.880: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:27.950: D/COMPAS(28509): comaps orientation:86
07-28 18:00:27.960: D/COMPASONDRAW(28509): direction: 86.0 width:105 height:105
07-28 18:00:28.000: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.030: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.070: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.070: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.140: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.150: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.200: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.210: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.260: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.280: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.320: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.320: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.390: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.400: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.460: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.470: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.520: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.530: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.580: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.600: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.640: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.650: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.710: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.720: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.770: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.790: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.840: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.860: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.900: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.900: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:28.960: D/COMPAS(28509): comaps orientation:87
07-28 18:00:28.970: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:29.030: D/COMPAS(28509): comaps orientation:87
07-28 18:00:29.030: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:29.080: D/COMPAS(28509): comaps orientation:87
07-28 18:00:29.100: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:29.160: D/COMPAS(28509): comaps orientation:87
07-28 18:00:29.160: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:29.220: D/COMPAS(28509): comaps orientation:87
07-28 18:00:29.220: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:29.280: D/COMPAS(28509): comaps orientation:87
07-28 18:00:29.300: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:29.350: D/COMPAS(28509): comaps orientation:87
07-28 18:00:29.360: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:29.400: D/COMPAS(28509): comaps orientation:87
07-28 18:00:29.410: D/COMPASONDRAW(28509): direction: 87.0 width:105 height:105
07-28 18:00:29.470: D/COMPAS(28509): comaps orientation:89
07-28 18:00:29.480: D/COMPASONDRAW(28509): direction: 89.0 width:105 height:105
07-28 18:00:29.530: D/COMPAS(28509): comaps orientation:95
07-28 18:00:29.550: D/COMPASONDRAW(28509): direction: 95.0 width:105 height:105
07-28 18:00:29.600: D/COMPAS(28509): comaps orientation:101
07-28 18:00:29.610: D/COMPASONDRAW(28509): direction: 101.0 width:105 height:105
07-28 18:00:29.740: D/COMPAS(28509): comaps orientation:113
07-28 18:00:29.740: D/COMPAS(28509): comaps orientation:120
07-28 18:00:29.750: D/COMPASONDRAW(28509): direction: 120.0 width:105 height:105
07-28 18:00:29.790: D/COMPAS(28509): comaps orientation:124
07-28 18:00:29.800: D/COMPASONDRAW(28509): direction: 124.0 width:105 height:105
07-28 18:00:29.860: D/COMPAS(28509): comaps orientation:128
07-28 18:00:29.870: D/COMPASONDRAW(28509): direction: 128.0 width:105 height:105
07-28 18:00:29.920: D/COMPAS(28509): comaps orientation:132
07-28 18:00:29.920: D/COMPASONDRAW(28509): direction: 132.0 width:105 height:105
07-28 18:00:29.980: D/COMPAS(28509): comaps orientation:134
07-28 18:00:29.980: D/COMPASONDRAW(28509): direction: 134.0 width:105 height:105
07-28 18:00:30.050: D/COMPAS(28509): comaps orientation:134
07-28 18:00:30.050: D/COMPASONDRAW(28509): direction: 134.0 width:105 height:105
07-28 18:00:30.100: D/COMPAS(28509): comaps orientation:134
07-28 18:00:30.120: D/COMPASONDRAW(28509): direction: 134.0 width:105 height:105
07-28 18:00:30.170: D/COMPAS(28509): comaps orientation:134
07-28 18:00:30.180: D/COMPASONDRAW(28509): direction: 134.0 width:105 height:105
07-28 18:00:30.230: D/COMPAS(28509): comaps orientation:133
07-28 18:00:30.230: D/COMPASONDRAW(28509): direction: 133.0 width:105 height:105
07-28 18:00:30.300: D/COMPAS(28509): comaps orientation:133
07-28 18:00:30.310: D/COMPASONDRAW(28509): direction: 133.0 width:105 height:105
07-28 18:00:30.370: D/COMPAS(28509): comaps orientation:133
07-28 18:00:30.380: D/COMPASONDRAW(28509): direction: 133.0 width:105 height:105
07-28 18:00:30.430: D/COMPAS(28509): comaps orientation:132
07-28 18:00:30.440: D/COMPASONDRAW(28509): direction: 132.0 width:105 height:105
07-28 18:00:30.480: D/COMPAS(28509): comaps orientation:133
07-28 18:00:30.500: D/COMPASONDRAW(28509): direction: 133.0 width:105 height:105
07-28 18:00:30.550: D/COMPAS(28509): comaps orientation:136
07-28 18:00:30.560: D/COMPASONDRAW(28509): direction: 136.0 width:105 height:105
07-28 18:00:30.610: D/COMPAS(28509): comaps orientation:142
07-28 18:00:30.620: D/COMPASONDRAW(28509): direction: 142.0 width:105 height:105
07-28 18:00:30.680: D/COMPAS(28509): comaps orientation:155
07-28 18:00:30.690: D/COMPASONDRAW(28509): direction: 155.0 width:105 height:105
07-28 18:00:30.740: D/COMPAS(28509): comaps orientation:172
07-28 18:00:30.770: D/COMPASONDRAW(28509): direction: 172.0 width:105 height:105
07-28 18:00:30.810: D/COMPAS(28509): comaps orientation:189
07-28 18:00:30.810: D/COMPASONDRAW(28509): direction: 189.0 width:105 height:105
07-28 18:00:30.870: D/COMPAS(28509): comaps orientation:198
07-28 18:00:30.880: D/COMPASONDRAW(28509): direction: 198.0 width:105 height:105
07-28 18:00:30.940: D/COMPAS(28509): comaps orientation:199
07-28 18:00:30.950: D/COMPASONDRAW(28509): direction: 199.0 width:105 height:105
07-28 18:00:31.000: D/COMPAS(28509): comaps orientation:195
07-28 18:00:31.020: D/COMPASONDRAW(28509): direction: 195.0 width:105 height:105
07-28 18:00:31.060: D/COMPAS(28509): comaps orientation:193
07-28 18:00:31.060: D/COMPASONDRAW(28509): direction: 193.0 width:105 height:105
07-28 18:00:31.120: D/COMPAS(28509): comaps orientation:192
07-28 18:00:31.130: D/COMPASONDRAW(28509): direction: 192.0 width:105 height:105
07-28 18:00:31.190: D/COMPAS(28509): comaps orientation:190
07-28 18:00:31.210: D/COMPASONDRAW(28509): direction: 190.0 width:105 height:105
07-28 18:00:31.250: D/COMPAS(28509): comaps orientation:189
07-28 18:00:31.270: D/COMPASONDRAW(28509): direction: 189.0 width:105 height:105
07-28 18:00:31.320: D/COMPAS(28509): comaps orientation:187
07-28 18:00:31.320: D/COMPASONDRAW(28509): direction: 187.0 width:105 height:105
07-28 18:00:31.380: D/COMPAS(28509): comaps orientation:183
07-28 18:00:31.380: D/COMPASONDRAW(28509): direction: 183.0 width:105 height:105
07-28 18:00:31.440: D/COMPAS(28509): comaps orientation:180
07-28 18:00:31.450: D/COMPASONDRAW(28509): direction: 180.0 width:105 height:105
07-28 18:00:31.510: D/COMPAS(28509): comaps orientation:177
07-28 18:00:31.530: D/COMPASONDRAW(28509): direction: 177.0 width:105 height:105
07-28 18:00:31.570: D/COMPAS(28509): comaps orientation:174
07-28 18:00:31.590: D/COMPASONDRAW(28509): direction: 174.0 width:105 height:105
07-28 18:00:31.630: D/COMPAS(28509): comaps orientation:171
07-28 18:00:31.650: D/COMPASONDRAW(28509): direction: 171.0 width:105 height:105
07-28 18:00:31.700: D/COMPAS(28509): comaps orientation:168
07-28 18:00:31.710: D/COMPASONDRAW(28509): direction: 168.0 width:105 height:105
07-28 18:00:31.760: D/COMPAS(28509): comaps orientation:166
07-28 18:00:31.770: D/COMPASONDRAW(28509): direction: 166.0 width:105 height:105
07-28 18:00:31.820: D/COMPAS(28509): comaps orientation:163
07-28 18:00:31.850: D/COMPASONDRAW(28509): direction: 163.0 width:105 height:105
07-28 18:00:31.890: D/COMPAS(28509): comaps orientation:161
07-28 18:00:31.890: D/COMPASONDRAW(28509): direction: 161.0 width:105 height:105
07-28 18:00:31.960: D/COMPAS(28509): comaps orientation:159
07-28 18:00:31.960: D/COMPASONDRAW(28509): direction: 159.0 width:105 height:105
07-28 18:00:32.010: D/COMPAS(28509): comaps orientation:157
07-28 18:00:32.030: D/COMPASONDRAW(28509): direction: 157.0 width:105 height:105
07-28 18:00:32.080: D/COMPAS(28509): comaps orientation:155
07-28 18:00:32.090: D/COMPASONDRAW(28509): direction: 155.0 width:105 height:105
07-28 18:00:32.140: D/COMPAS(28509): comaps orientation:153
07-28 18:00:32.140: D/COMPASONDRAW(28509): direction: 153.0 width:105 height:105
07-28 18:00:32.210: D/COMPAS(28509): comaps orientation:152
07-28 18:00:32.220: D/COMPASONDRAW(28509): direction: 152.0 width:105 height:105
07-28 18:00:32.270: D/COMPAS(28509): comaps orientation:150
07-28 18:00:32.280: D/COMPASONDRAW(28509): direction: 150.0 width:105 height:105
07-28 18:00:32.340: D/COMPAS(28509): comaps orientation:149
07-28 18:00:32.360: D/COMPASONDRAW(28509): direction: 149.0 width:105 height:105
07-28 18:00:32.400: D/COMPAS(28509): comaps orientation:147
07-28 18:00:32.410: D/COMPASONDRAW(28509): direction: 147.0 width:105 height:105
07-28 18:00:32.470: D/COMPAS(28509): comaps orientation:146
07-28 18:00:32.470: D/COMPASONDRAW(28509): direction: 146.0 width:105 height:105
07-28 18:00:32.530: D/COMPAS(28509): comaps orientation:145
07-28 18:00:32.530: D/COMPASONDRAW(28509): direction: 145.0 width:105 height:105
07-28 18:00:32.590: D/COMPAS(28509): comaps orientation:144
07-28 18:00:32.600: D/COMPASONDRAW(28509): direction: 144.0 width:105 height:105
07-28 18:00:32.670: D/COMPAS(28509): comaps orientation:143
07-28 18:00:32.690: D/COMPASONDRAW(28509): direction: 143.0 width:105 height:105
07-28 18:00:32.720: D/COMPAS(28509): comaps orientation:142
07-28 18:00:32.740: D/COMPASONDRAW(28509): direction: 142.0 width:105 height:105
07-28 18:00:32.780: D/COMPAS(28509): comaps orientation:141
07-28 18:00:32.800: D/COMPASONDRAW(28509): direction: 141.0 width:105 height:105
07-28 18:00:32.850: D/COMPAS(28509): comaps orientation:140
07-28 18:00:32.850: D/COMPASONDRAW(28509): direction: 140.0 width:105 height:105
07-28 18:00:32.900: D/COMPAS(28509): comaps orientation:140
07-28 18:00:32.910: D/COMPASONDRAW(28509): direction: 140.0 width:105 height:105
07-28 18:00:32.970: D/COMPAS(28509): comaps orientation:139
07-28 18:00:32.970: D/COMPASONDRAW(28509): direction: 139.0 width:105 height:105
07-28 18:00:33.030: D/COMPAS(28509): comaps orientation:138
07-28 18:00:33.040: D/COMPASONDRAW(28509): direction: 138.0 width:105 height:105
答案 0 :(得分:0)
根据Android开发者View:
通过遍历树并渲染与无效区域相交的每个视图来处理绘图。因为树是按顺序遍历的,这意味着父母将在他们的孩子之前(即后面)绘制,兄弟姐妹按照他们出现在树中的顺序绘制。如果为View设置了一个可绘制的背景,那么View会在回调它的onDraw()方法之前为你绘制它。
请注意,框架不会绘制不在无效区域中的视图。
要强制绘制视图,请调用invalidate()。
这可能也会有所帮助:https://plus.google.com/u/0/+ArpitMathur/posts/cT1EuBbxEgN
答案 1 :(得分:0)
你想在哪里设置绘图的实际图像?在您的示例中,您只设置了android:background
,但背景未在onDraw方法中绘制。它继承自View并在View#draw(Canvas)方法中绘制(同样的方法在绘制背景后的某个时刻调用onDraw)
P.S。您还应该使用canvas.save()/ restore()方法调用将操作包装到canvas中,以防有人扩展您的组件并尝试绘制某些内容(因此他们不会因轮换而感到惊讶)