2

I am trying to change the height of the view programmatically.
What i have tried is -

RelativeLayout rlOne;
rlOne = (RelativeLayout) findViewById(R.id.rlOne);

And on some click event i am changing the height using the LayoutParams.

rlOne.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, NEWHEIGHT));

The height is increased but the transition is not smooth.
How can i achieve a smooth transition from view's original height to view's new height?
Can i slow down the transition ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Anukool
  • 5,301
  • 8
  • 29
  • 41

4 Answers4

2

Basically the idea is that, you calculate the new height (the height after your view increasing) view first and write an thread, increase the height of you old view (the height of your view before increasing) pixel by pixel(may be 5-10 pixels at a time) until it reaches the new height. Hope the idea could help.

user2652394
  • 1,686
  • 1
  • 13
  • 15
1

Play with from/to/speed values

ScaleAnimation scaleAnimation = new ScaleAnimation(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rlOne.setAnimation(scaleAnimation);

Source:

https://stackoverflow.com/a/1624689/1276374

Community
  • 1
  • 1
Boris Mocialov
  • 3,439
  • 2
  • 28
  • 55
  • is there any thing except scale because if i scale the textView from one side, it does not look decreasing width, it look like comprising – Furqan Jul 31 '17 at 16:31
0

You could write a for loop, where the view's height is increased by very little, than a pause is made before increasing the counter. In this way, the user will have the impression of a smooth transition.

Radu
  • 384
  • 4
  • 15
-2

Use

LinearLayout linearLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                            LayoutParams.WRAP_CONTENT);
Master
  • 2,945
  • 5
  • 34
  • 65
  • Doesn't compile, you're assigning a reference to an Object of type `LinearLayout.LayoutParams` to a variable of type `LinearLayout`. – urgentx May 23 '18 at 22:15