我想在小部件上绘制画布,但是没有任何效果。我有一个带有ImageView的表单,其中包含位图,我将在其中绘制所有美丽,但它没有绘制...这是我的一段代码,为什么它不起作用?
我的提供程序,在那里我进行绘制。
public class MainActivity extends AppWidgetProvider {
private Bitmap bmp;
private RemoteViews views;
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
views = new RemoteViews(context.getApplicationContext().getPackageName(), R.layout.main);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
paint.setTextSize(16);
paint.setAntiAlias(true);
paint.setTypeface(Typeface.MONOSPACE);
Bitmap bmp = Bitmap.createBitmap(100, 16, Bitmap.Config.ALPHA_8);
Canvas c = new Canvas(bmp);
c.drawText("fdgfdgfdgfdfdfdgGFDFGFDDDDG", 0, 0, paint);
views.setImageViewBitmap(R.id.imageView1, bmp);
}
还有我的main.xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dip"
android:background="@drawable/ic_launcher" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ImageView>