I have a 4×1 widget that holds several ImageView views inside a LinearLayout. I want to be able to have. I want to be able to adjust the width of those views depending on the screen resolution of the device where the app is installed. My goal is to have each view be the same width, and to have them uniformly distributed across the width of the widget. And I’d like it to fill up the whole width of the widget (so that if the widget covers more space on high resolution devices, each ImageView would be wider). I don’t want to create different XML layouts for each device type (mdpi, hdpi, xhdpi, etc) — I’d like to have this done programmatically when the widget is set up (or updated). But I can’t find any documentation in RemoteViews that allows me to change the width of a view. So is there a way to do this?
I have a 4×1 widget that holds several ImageView views inside a LinearLayout .
Share
It’s not necessary to do it at runtime.
You can use the
android:layout_weighttag in your XML file. If you set the weight to1and set each image to0dp, the images will be the exact same width. That way you won’t need to create different layouts for each screen size.