上的小工具设置ImageView的宽度和高度编程(Set ImageView width and h

2019-07-20 19:54发布

我使用下面的代码来设置使用远程视窗现在我想设置高度和宽度的ImageView运行一个小部件的ImageView的图像。

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);
}

Answer 1:

您可以设置布局PARAMS progrematiclly是这样的:

myImageView.setLayoutParams(new 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 = new LinearLayout.LayoutParams(30, 30);
myImageView.setLayoutParams(layoutParams);

更新:下面的帖子来帮助你完成你所需要的:

RemoteViews setLayoutParams?

http://pastebin.com/As3L8xWu



Answer 2:

喜尝试这些行设置ImageView的宽度和高度

image_view.getLayoutParams().height = 20;

image_view.getLayoutParams().width = 100;


Answer 3:

这应该工作!

image.getLayoutParams().height = 90;



文章来源: Set ImageView width and height programmatically on a widget