这是,什么有效:
a) 在 main.xml 中有两个 ImageView 的 FrameLayout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/frameLayout1"
android:layout_height="wrap_content">
<ImageView android:src="@drawable/radar_background"
android:id="@+id/background" android:layout_width="wrap_content"
android:layout_height="wrap_content"></ImageView>
<ImageView android:src="@drawable/radar_sector" android:id="@+id/sector"
android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</FrameLayout>
b) 在背景上旋转动画,而前景扇区保持不变
因为我需要对背景图像做更多的事情,所以我将它放入 FrameLayout 子类并相应地更改了 main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/frameLayout1"
android:layout_height="wrap_content">
<com.decades.SensorTest.RadarView
android:id="@+id/background" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView android:src="@drawable/radar_sector" android:id="@+id/sector"
android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</FrameLayout>
这是新的 RadarView.java:
public class RadarView extends FrameLayout {
private Bitmap mRadar;
public RadarView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public RadarView(Context context) {
super(context);
init();
}
private void init() {
mRadar = BitmapFactory.decodeResource(getResources(), R.drawable.radar_background);
}
@Override
public void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
canvas.drawBitmap(mRadar, 0, 0, null);
}
}
发生什么了:
a) 在 setContentView(R.layout.main) 期间调用构造函数;
b) 调用 dispatchDraw 覆盖
c) 图像没有出现在屏幕上...
有没有人看到,为什么?