user2877611
user2877611

Reputation: 21

Android - How to keep the view position not change after calling setVisible(View.GONE)?

I have a RootLayout[it can be setted any layout],such as:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainRootLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageButton
        android:id="@+id/ibtnHidden"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"

        android:src="@android:drawable/ic_menu_add" />

    <ImageButton
        android:id="@+id/ibtnPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/ibtnHidden"
        android:layout_marginLeft="9dp"
        android:layout_toRightOf="@+id/ibtnHidden"
        android:src="@android:drawable/ic_media_play" />

    <ImageButton
        android:id="@+id/ibtnPreference"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/ibtnHidden"
        android:layout_marginLeft="9dp"
        android:layout_toRightOf="@+id/ibtnPlay"
        android:src="@android:drawable/ic_menu_preferences" />

    <ImageButton
        android:id="@+id/ibtnExit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/ibtnHidden"
        android:layout_marginLeft="9dp"
        android:layout_toRightOf="@+id/ibtnPreference"
        android:src="@android:drawable/ic_menu_close_clear_cancel" />

</RelativeLayout>

ibtn_Hidden = (ImageButton) view.findViewById(R.id.ibtnHidden);
ibtn_Play = (ImageButton) view.findViewById(R.id.ibtnPlay);
ibtn_Preference = (ImageButton) view.findViewById(R.id.ibtnPreference);
ibtn_Exit = (ImageButton) view.findViewById(R.id.ibtnExit);

when I call "ibtn_Play.setVisible(View.GONE);ibtn_Preference.setVisible(View.GONE);ibtn_Exit.setVisible(View.GONE)",the ibtn_Hidden's position would changed.

I guess it is because the others have been temporarily removed,the view's size is also changed,and it is towards the middle of change.

How to keep the ibtn_Hidden's position not change after calling setVisible(View.GONE),and the others[ibtn_Play ibtn_Preference ibtn_Exit] should not occupy space?Thank you~

Upvotes: 0

Views: 990

Answers (2)

Bilal Shahid
Bilal Shahid

Reputation: 1

yes u can use view.visible if your parent position disturb i used view.gone so my parent position disturbs it goes up but in view.visible it remain constant

Upvotes: 0

Gil Moshayof
Gil Moshayof

Reputation: 16761

If you want a view to not be visible, but still keep it's layout impact, you can use this:

imageButton2.setVisibility(View.INVISIBLE);

Hope this helps :)

Upvotes: 1

Related Questions