我试图在小部件上绘制画布,但我什么都没有.我有一个带有imageviev的表格,其中的位图,我将绘制所有的美丽,但它没有绘制……这是我的一段代码,它不起作用?
我画的提供商
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
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" >
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
解决方法:
尝试为x和y设置不同的值.目前它正在绘制但是超出了位图的界限…所以试试..
标签:java,android,xml,widget
来源: https://codeday.me/bug/20190626/1291179.html