complez
complez

Reputation: 8332

android setvisibility gone does not release space

I have a relative layout with one textview and two images (width fixed width, height = 48dip). When I setvisibility view.gone for one image, it does not release the space

enter image description here

<TextView
    android:id="@+id/tv_subject_name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="18dip"
    android:textColor="#333"
    android:text="This is subject name"
    android:background="@android:color/transparent"
    android:layout_toLeftOf="@+id/btn_edit"
    android:layout_centerVertical="true"
    android:layout_marginRight="10dip"
    android:maxLines="1"/>
<EditText
        android:id="@+id/et_subject_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="18dip"
        android:textColor="#333"
        android:layout_toLeftOf="@+id/btn_edit"
        android:layout_centerVertical="true"
        android:enabled="false"
        android:visibility="invisible"
        android:background="@android:color/transparent"
        android:layout_marginRight="10dp"
        android:singleLine="true"
        />

<ImageView
        android:layout_width="48dip"
        android:layout_height="48dip"
        android:id="@+id/btn_edit"
        android:layout_alignParentRight="false"
        android:layout_centerVertical="true"
        android:src="@drawable/edit_blue"
        android:background="#eee"
        android:visibility="visible"
        android:layout_toLeftOf="@+id/btn_quick_reply"/>

<ImageView
        android:layout_width="48dip"
        android:layout_height="48dip"
        android:id="@+id/btn_quick_reply"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/edit_quick_reply_blue"
        android:background="#eee"
        android:visibility="visible"/>

Upvotes: 2

Views: 1086

Answers (1)

SimonSays
SimonSays

Reputation: 10977

For what you want to do, i would use a LinearLayout instead of a RelativeLayout. something like that:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ...>

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        ....>

    <ImageView
        android:id="@+id/img1"
        android:layout_width="48dip"
        android:layout_height="48dip"
        ...>
    <ImageView
        android:id="@+id/img2"
        android:layout_width="48dip"
        android:layout_height="48dip"
        ...>
</LinearLayout>

Upvotes: 1

Related Questions