I have a layout that I want to expand after button click, as shown below:
The problem is I need to use Animation, so I decided to use View.animate.translationY()
. Here is my code:
private void showBottomThreeLines(boolean show){
if(show)
mShiftContainer.animate().translationY(0);
else
mShiftContainer.animate().translationY(-(mFifthLineContainer.getHeight() * 3));
}
However, this is what I get after testing:
The current height is still the same as the previous height! The view's height is using MATCH_PARENT
. I even tried to change it to 1000dp
, but it still has the same height. How do I update view's height during translationY()
animation?
After doing some research, I find out that defining view height after its translation will not increase its height at all. It appears that the sum of the entire view's height CANNOT go exceed its parent layout's height. Which means, if you set parent layout's height as
MATCH_PARENT
and your screen size is 960 dp, your child view's maximum height will be 960 dp, even if you define its height, e.g.android:layout_height="1200dp"
.Therefore, I decided to dynamically re-size parent layout's height, and make the footer layout's height
MATCH_PARENT
. By default, my parent layout's height isMATCH_PARENT
, but I call below method ononCreateView()
:This will make my footer layout become off-screen. Then I tried to use
View.animate().translationY()
, but then I got another problem! There is a bug in Android animation that causes flicker when you callView.setY()
ononAnimationEnd()
. It seems the cause isonAnimationEnd()
is being called before the animation truly ends. Below are references that I use to solve this problem:Android Animation Flicker
Android Flicker when using Animation and onAnimationEnd Listener
Therefore, I changed my
showBottomThreeLines()
method: