Set ImageView width and height programmatically on a widget

后端 未结 3 2166
梦如初夏
梦如初夏 2020-12-30 06:17

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 != AppW         


        
相关标签:
3条回答
  • 2020-12-30 06:23

    This should work!

    image.getLayoutParams().height = 90;

    0 讨论(0)
  • 2020-12-30 06:31

    hi try these line to set imageview width and height

    image_view.getLayoutParams().height = 20;
    
    image_view.getLayoutParams().width = 100;
    
    0 讨论(0)
  • 2020-12-30 06:46

    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 get image 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:

    RemoteViews setLayoutParams?

    http://pastebin.com/As3L8xWu

    0 讨论(0)
提交回复
热议问题