我想从 url 加载图像,以及图像下方显示的文本。像这样,
ImageView 和 TextView 上的对齐,这是我的代码,但没有显示所需的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00FFFF" android:padding="0.1dp"> <TextView android:text="@string/widgetUrl" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.8" android:layout_gravity="center_vertical" android:textColor="#000000"> </TextView> <TextView android:text="@string/widgetTitle" android:id="@+id/widgetTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.8" android:layout_gravity="center_vertical" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:textColor="#ffffff"> </TextView> <ImageView android:id="@+id/widgetBackground" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" android:src="@drawable/ic_launcher" android:layout_gravity="center_vertical"> </ImageView> </LinearLayout>
如何从 web 加载图像并在 java 代码中的布局上显示?以下是我的小部件提供程序代码:
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); Log.i(WIDGETTAG, "onUpdate"); final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; Log.i(WIDGETTAG, "updating widget[id] " + appWidgetId); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); /* View setup */ views.setInt(R.id.widgetTitle, "setBackgroundColor", Color.argb(150, 0, 0, 0)); Intent intent = new Intent(context, ChopInkService.class); intent.setAction(ChopInkService.UPDATE_IMAGE); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widgetBackground, pendingIntent); Log.i(WIDGETTAG, "pending intent set"); // Tell the AppWidgetManager to perform an update on the current App Widget appWidgetManager.updateAppWidget(appWidgetId, views); }
Service和AppWidgetProvider的工作是什么?
- 从 url 加载图像是service还是AppWidgetProvider的工作?
- 视图设置应该投入服务还是AppWidgetProvider?
当用户点击小部件时,如何将用户重定向到播放商店?
先谢谢了。我是新手,如果我问了一个愚蠢的问题,请道歉。