Java – get wrap_ Content height
•
Java
My goal is to animate an invisible linear layout when a specific button is clicked To do this, I set the default height to wrap_ Content, get the height when the application starts, set the height to 0, and start the animation when you click the button This 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); } });
It's a good job, but I want to do something different I want the default height to be 0 and then calculate wrap_ Content height and pass it to:
Animation ani = new ShowAnim(linearLayout,height/* target layout height */);
How can I do that? I searched but found something
Solution
Try this Code:
linearLayout.measure(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); height = linearLayout.getMeasuredHeight();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码