问题描述
我使用跌破code。使用远程视窗现在我想设置高度和宽度的ImageView运行时设置的一个小部件ImageView的图像。
如果(appWidgetId!= AppWidgetManager.INVALID_APPWIDGET_ID){
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(WidgetActivity1_1.this);
RemoteViews remoteViews =新RemoteViews(WidgetActivity1_1.this.getPackageName(),R.layout.widget_layout1_1);
意图configIntent =新的意图(WidgetActivity1_1.this,UpdateWidgetService.class);
configIntent.putExtra(APPID,appWidgetId);
PendingIntent configPendingIntent = PendingIntent.getService(WidgetActivity1_1.this,appWidgetId,configIntent,0);
remoteViews.setImageViewResource(R.id.imgviewGrow,R.drawable.flower1);
}
您可以设置布局PARAMS progrematiclly是这样的:
myImageView.setLayoutParams(新ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
或者设置一些吧。
图片大小的操作有时可能非常棘手,它的建议首先得到图像布局参数,可以改变它,设置回:
android.view.ViewGroup.LayoutParams的LayoutParams = myImageView.getLayoutParams();
layoutParams.width = 30;
layoutParams.height = 30;
myImageView.setLayoutParams(的LayoutParams);
如果你仍然有问题,来改变它的大小尽量把它的LinearLayout内,并使用布局PARAMS操作ImageView的大小:
LinearLayout.LayoutParams的LayoutParams =新LinearLayout.LayoutParams(30,30);
myImageView.setLayoutParams(的LayoutParams);
更新:以下职位来帮助你完成你所需要的:
I am using below code to set an image on a widget imageview using remoteview now i want to set height and width to imageview runtime.
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(WidgetActivity1_1.this);
RemoteViews remoteViews = new RemoteViews(WidgetActivity1_1.this.getPackageName(), R.layout.widget_layout1_1);
Intent configIntent = new Intent(WidgetActivity1_1.this,UpdateWidgetService.class);
configIntent.putExtra("Appid", appWidgetId);
PendingIntent configPendingIntent = PendingIntent.getService(WidgetActivity1_1.this, appWidgetId, configIntent, 0);
remoteViews.setImageViewResource(R.id.imgviewGrow, R.drawable.flower1);
}
You can set the Layout Params progrematiclly this way:
myImageView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
or set a number instead.
Image size manipulation sometimes maybe tricky and it's recommended to first getimage layout params, change it and set it back:
android.view.ViewGroup.LayoutParams layoutParams = myImageView.getLayoutParams();
layoutParams.width = 30;
layoutParams.height = 30;
myImageView.setLayoutParams(layoutParams);
and if you still have a problem to change it's size try to put it inside of a LinearLayout and manipulate the imageView size using the layout params:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
myImageView.setLayoutParams(layoutParams);
Update: The following posts should help you with what you need:
这篇关于在一个小部件设置ImageView的宽度和高度编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!