My app shows a widget with a total of 8 buttons. I would like to give the user the possibility to style that widget and customize the size of the ImageViews which are below the buttons. The aim is to leave the Buttons as they are, but to change the ImageView sizes dynamically.
For this the User gets to set an icon Size, which is stored in a SharedPreference as an Integer iconSize.
How can I change the size of an ImageView in a Widget?
For now, the ImageViews are created with the size set in the xml file. How can I achieve a redraw with another size?
I assume there is not much code to post here but I will be glad to do so if necessary, just tell me if you have an idea what code could help here.
What I don't want to do:
resize the entire widget
create tons of layout files to switch according to the iconSize
Some Code:
This is how I set the ImageView size in my activity as a preview of the widget. icons is an array of ImageViews, progress refers to a ProgressBar that is used to choose iconSize.
for (ImageView icon : icons) {
icon.requestLayout();
// convert into actual Pixels
progress = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_PX,
progress,
getResources().getDisplayMetrics()
);
// set width and height
icon.getLayoutParams().height = progress;
icon.getLayoutParams().width = progress;
sizeText.setText("" + progress);
}
iconSize
control? Would you be pulling in different icons that happen to be different sizes, with yourandroid:layout_width
andandroid:layout_height
set towrap_content
? Would you be using the same icons, but usingandroid:layout_width
andandroid:layout_height
to control the size? Would you be doing something else? That would help us visualize the effect that you are seeking. – GreeneLayoutParams
in aRemoteViews
, other than through the initial load in the constructor. – Greene