How to set height to wrap content in the adapter

Is there a way to set layout height to wrap content on the adapter?
The layout that I inflate in my adapter has two parts. One of the parts is visible while the other one is gone, but both of them has wrap_content for the height. Like:

android:visibility="gone" >
  android:visibility="visible" />
  android:visibility="gone" />

Now, with a press of a button, the second view’s visibility will be set to visible. But problem is that it doesn’t wrap it’s content. The height it only uses is the height from the first view, the one who’s already visible.

I tried to set:

view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

next after I set the view’s visibility to visible, but it did not work.

So, is there a way? Or can you suggest any workaround? Thank you so much.

Source: android

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.