Skip to content Skip to sidebar Skip to footer

Setlayoutparams Doesn't Work Second Time

I have written the following code to first increase the size of ImageView and after 100ms decrease the size of the same ImageView. However this code increases the size of ImageView

Solution 1:

You change the layout 2 times in the same UI thread, so only the last change can take effect. You should separate to 2 UI thread, like this:

uiHandler.post(newRunnable()
{
    @Overridepublicvoidrun()
    {
        FrameLayout.LayoutParamslayout= (android.widget.FrameLayout.LayoutParams) imageView.getLayoutParams();
        layout.height = (int) (2*iconsSizeInDP);
        layout.width = (int) (2*iconsSizeInDP);
        imageView.setLayoutParams(layout);
    }
};
uiHandler.postDelayed(newRunnable()
{
    @Overridepublicvoidrun()
    {
        Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
        // following code block doesnt'affect imageView dimensions
        layout.height = (int) iconsSizeInDP;
        layout.width = (int) iconsSizeInDP;
        imageView.setLayoutParams(layout);
    }
},50);

Solution 2:

please have a look on the line FrameLayout.LayoutParams layout = (android.widget.FrameLayout.LayoutParams) imageView.getLayoutParams();

please have a look when have a try to make FrameLayout.LayoutParams layout global

Post a Comment for "Setlayoutparams Doesn't Work Second Time"