0

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" />
Octavian Helm
39.6k19 gold badges100 silver badges102 bronze badges
asked Jan 28, 2011 at 18:27

1 Answer 1

3

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.

answered Jan 28, 2011 at 18:55
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.