Visibility of Gone takes still space of particular control in android?
Asked Answered
C

2

2

I am using the LinearLayout and inside there's button I am making visibilty gone based on supported states. SupportedStatuses are true then making Button as Visible but SupprtedStatuse are false then making button as Gone.

This is in a header and Button is Gone but still takes up the space. Here is the Layout which I am using.

<LinearLayout
            android:id="@+id/llparentView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content
            android:orientation="vertical">
      <Button
            android:id="@+id/btn_change_status"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
</LinearLayout>

Anybody have a good solution then it helps me a lot.

Christianson answered 21/5, 2015 at 7:45 Comment(10)
do you change the visibility programmatically ?Derosa
setVisibility to linear layout instead of buttonAdnah
yes.. changing the visibility programmatically .. @ BlackbeltChristianson
I can't setVisibilty to linear layout there are other controls as well..Christianson
I am on same screen and problem existsChristianson
Does removeView help me ? and how ?Christianson
Why do you need a linearlayout around your button?Breedlove
It's my parentLayout there are other view such as Textviews etc..Christianson
#12302672 - UI point of view this problem currently facing.Christianson
Possible duplicate of setVisibility(GONE) view becomes invisible but still occupies spacePrototherian
T
1

You could use a FrameLayout around whatever layout you are using For example:

<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content">

    <!-- put your views here -->
</FrameLayout>

This will ensure when using View.GONE the FrameLayout collapses on the space.

Tardy answered 1/7, 2017 at 19:17 Comment(0)
S
-1

Try to wrap your button in another Linear/Frame layout and change their visibility as well.

Spinney answered 1/7, 2017 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.