1
我試圖在App Widget中將畫布繪製的位圖渲染到ImageView上。無法得到這個工作,我正在嘗試一個更簡單的例子,沒有RemoteViews對象,所以只是試圖渲染一些矩形到畫布中,然後在ImageView上進行設置。我只看到一個空白的活動。下面是代碼示例:無法將ImageImageBitmap從Canvas位圖設置到ImageView上
LinearLayout layout = new LinearLayout (this);
layout.setDrawingCacheEnabled(true);
try
{
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint red = new Paint();
red.setColor(0xCC0000);
Paint blue = new Paint();
blue.setColor (0x0099CC);
canvas.drawRect(0, 0, 100, 100, red);
int percent = 55;
canvas.drawRect(0, 0, percent, 100, blue);
ImageView imageView = new ImageView (this);
imageView.setDrawingCacheEnabled(true);
imageView.setImageBitmap(bitmap);
imageView.setAdjustViewBounds(true);
imageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
layout.addView(imageView);
}
catch(Exception e)
{
Log.e("ElectionForecastWidgetProvider", "error with bar", e);
}
this.setContentView(layout);
我已經調整各個部位,如試圖走出setDrawingCacheEnabled方法,堆棧過低及在其他地方尋找後。任何人都可以提供任何見解嗎?謝謝!
好的 - 酷!那看起來就是這個問題,謝謝Harism! – Bennidhamma