There is one ImageView
in my homescreen widget. In the layout file, I am setting the height and width to wrap_content
. But depending on user's input, I have to change its height and width to match_parent
. How can this be done ?
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
Now I tried to use the setInt()
method on this RemoteViews
object like this to just check if it is possible to change height and width:
rv.setInt(R.id.widgetImageView, "setMinimumHeight", 300);
But this is what I get on the logcat:
couldn't find any view, using error view
android.widget.ImageView can't use method with RemoteViews: setMinimumHeight(int)
So how do I change its height and width to match_parent
?
For those wondering how this can be done, I used two
ImageView
in the layout. One with height and width set towrap_content
and another with height and width set tomatch_parent
. Depending on the user's input, I called thesetVisibility
to hide theImageView
which was not required throughRemoteView
.There are a very few
ImageView
methods which we can call throughRemoteView
.Use:
First parameter of
LayoutParams
is for width, second for height.Here, I have created a new ImageView for explanation. You should use your own ImageView variable from your code, to do the above. I hope that's clear.
[Update to code]: Sorry, the
MATCH_PARENT
variable is underLayoutParams
not underView
. I've updated the code.[Update]: Above answer does not work for
RemoteViews
asRemoteViews
cannot have Layout Params. Based on the answer given in this SO Question, there is no way to set or find dimensions for RemoteViews by normal methods.I found this Android Widget Tutorial, where under the section Widget Size, the author says:
From this, I can suggest you that instead of setting a specific integer size value directly, why not set the number of rows and columns to resize? For example, if your initial widget size was
4 Columns and 1 Row
, then on user input, you can change it to4 Columns and 4 Rows
, thus making it occupy the whole screen (Max size for widgets is 4 Rows and 4 Columns)I know the above method is not what you wanted, but this seems like the only way to me. Try and see if it's helpful.