2012-03-13 7 views
0

私はカスタムビューを作成し、ビットマップイメージを描画しました。どのように私は私のwidget..Belowでこのビューを使用することができ、コード残念ながらウィジェットでビューを使用する

public class MyWidget extends AppWidgetProvider { 

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
    for(int i=0 ; i<appWidgetIds.length; i++) { 

     int appWidgetId = appWidgetIds[i]; 

     RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main); 

     views.setImageViewBitmap( ...); 

     appWidgetManager.updateAppWidget(appWidgetId, views); 

    } 

} 

} 



public class myCustomView extends View { 
Bitmap img; 

public myCustomView(Context context) { 
    super(context); 
    img = BitmapFactory.decodeResource(context.getResources(), R.drawable.myimg); 

} 

protected void onDraw(Canvas canvas) { 

    canvas.drawBitmap(img, 0, 0, new Paint()); 

} 

答えて

1

である、あなたは、ホームスクリーンウィジェットでカスタムビューを使用することはできません。

レイアウトには、FrameLayout、LinearLayout、RelativeLayoutを使用できます。ビューとして、AnalogClock、Button、Chromometer、ImageButton、ImageView、ProgressBar、およびTextViewを使用できます。

Android 3.0以降では、GridView、ListView、StackView、ViewFlipper、およびAdapterViewFlipperが追加で利用できます。

Source

関連する問題