2012-03-13 50 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