0

I'm trying to write a code that resizes a view's width and height by animating it, and to do that, what I've done is getting LayoutParams of the view once, and every 16 ms get a width and a height value from an int[] and change the width and height of the LayoutParams using them, and finally do view.setLayoutParams(layoutParams); to change the view's size.

This works fine, but it takes a little too much to .setLayoutParams(), and so when I give it a duration value of 1000 ms, it takes around 1500 ms to finish animating.

You can see my code fully here. (P.S the code is not finished yet and I'm aware of it's problems)

Is there an alternative way to set width and height to a view that is faster? I thought about setting margin, but that has limitations for what I'm trying to do. Thanks.

SIMMORSAL
  • 1,402
  • 1
  • 16
  • 32
  • Did you ever find a solution to this? – saltandpepper Feb 19 '18 at 12:58
  • @saltandpepper unfortunately no. But i tested it on some widgets (not thoroughly) and found out that it's OK to use on `TextViews` (gives a 30 - 40 fps on 1440p screens and 40 - 50 on 1080p) but not on `ImageViews` (on 1440p gives you a 10 - 20 fps first time you run it, and each time after that fps gets reduced. I was around 1 - 2 fps the 10th iteration). Using it on a say `LinearLayout` with some widgets in it, all with fixed sizes will be pretty smooth. – SIMMORSAL Feb 21 '18 at 01:09
  • I've found that using View.setScaleX and View.setScaleY work well as well (for me it is in the context of a CoordinatorLayout and a custom CoordinatorLayout.Behaviour, that scales and moves an ImageView based on the scrollstate). – saltandpepper Feb 21 '18 at 09:59

0 Answers0