I am using a header that includes two TextViews in the center and to the left of the TextView I am having two Buttons and to right of the TextView I am having two Buttons. All these four Button's visibility is set to gone.
Button 1 (gone) -- Button 2 (gone) -- Textview 1 -- TextView 2 -- Button 3 (gone) -- Button4 (gone)
The problem is that if I make only Button 1 visible the TextView appears in the center if I make only Button 2 visible my TextView moves closer to Button 2.
What I want is that my `TextView' is always centerd.
How can I do that?
My code is:
<Button android:id="@+id/back"
android:background="@drawable/back"
android:layout_marginLeft="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<Button android:id="@+id/allcities"
android:background="@drawable/campusbttn"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<TextView android:id="@+id/quaddeal_header_text"
android:layout_width="50dip"
android:layout_height="30dip"
android:layout_centerHorizontal="true"
android:text="Quad"
android:textSize="20sp"
android:textColor="@color/green"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/allcities" />
<TextView android:id="@+id/quaddeal_header_text_add"
android:layout_width="50dip"
android:layout_height="30dip"
android:layout_centerHorizontal="true"
android:text="Deals"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@color/green"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/quaddeal_header_text" />
<Button android:id="@+id/quad_share"
android:background="@drawable/share"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<Button android:id="@+id/quad_login"
android:background="@drawable/button_img"
android:text="Login"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
1 Answer 1
Don't set the Button's visibility to gone but to invisible. If you set the visibility to gonethen the entire space that View would take up is gone which in your case moves your other Views around.
However you should rethink your layout a bit.