My purpose is to have an invisible LinearLayout that appear whit an animation when click on a specific button. To do this i have set the default height to WRAP_CONTENT, get the height when the app start, set the height to 0 and start the animation when i click on the button. Here is the code:
linearLayout.post(new Runnable() {
@Override
public void run(){
height = linearLayout.getMeasuredHeight();
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 0));
}
});
findViewById(R.id.btnOperator).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation ani = new ShowAnim(linearLayout, height/* target layout height */);
ani.setDuration(1000/* animation time */);
linearLayout.startAnimation(ani);
}
});
This work pretty good, but i want to do different. I want that the default height is 0, and then calculate what the WRAP_CONTENT height would be, and pass it to:
Animation ani = new ShowAnim(linearLayout, height/* target layout height */);
How could i do this? I searched but found anything.
Try this code:
linearLayout.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
height = linearLayout.getMeasuredHeight();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With