Relativelayout and View Gone

constraint layout visibility=gone
android:visibility=gone not working
setvisibility(gone) view becomes invisible but still occupies space
android:layout_alignwithparentifmissing
android:visibility=visible
visibility in android studio
how to visible and invisible layout in android
android:layout_below

I have a layout like this:

You can see the little play icon there. What i want is if i give visibility gone to this little play icon, my view should look like this:

But my current status of if i give to visibility gone to little play icon:

My xml:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="76dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/conversation_list_border">

    <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/image"
        android:layout_width="62dp"
        android:layout_height="62dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="6dp"
        android:src="@drawable/default_color_1" />


    <TextView
        android:id="@+id/nameText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@+id/image"
        android:text="Tolgay Toklar"
        android:textColor="#727272"
        android:textSize="13sp"
        android:textStyle="bold" />

    <RelativeLayout
        android:id="@+id/unreadMessageBg"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignParentRight="true"
        android:layout_marginTop="30dp"
        android:layout_marginRight="22dp"
        android:background="@drawable/konusmalar_chat_count_bg">

        <TextView
            android:id="@+id/unreadMessageCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:fontFamily="sans-serif"
            android:text="5"
            android:textColor="@color/white"
            android:textSize="12sp"
            android:textStyle="bold" />

    </RelativeLayout>

    <TextView
        android:id="@+id/bioText"
        android:layout_width="199dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/nameText"
        android:layout_marginStart="2dp"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="5dp"
        android:layout_toStartOf="@+id/imageView7"
        android:layout_toLeftOf="@+id/imageView7"
        android:layout_toEndOf="@+id/imageView22"
        android:layout_toRightOf="@+id/imageView22"
        android:maxLines="1"
        android:text="Selam Nasılsın?Selam Nasılsın?Selam Nasılsın?Selam Nasılsın?"
        android:textColor="#7A7A7A"
        android:textSize="15sp"
        android:textStyle="normal" />

    <ImageView
        android:id="@+id/imageView22"
        android:layout_width="18dp"
        android:layout_height="18dp"
        android:layout_below="@+id/nameText"
        android:layout_alignStart="@+id/nameText"
        android:layout_alignLeft="@+id/nameText"
        android:layout_marginStart="0dp"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="6dp"
        android:layout_marginRight="3dp"
        app:srcCompat="@drawable/send_voice_record" />

</RelativeLayout>

How can i resolve this problem?


Put the imageView22 and bioText into another layout. The key point is to set android:layout_alignWithParentIfMissing="true" for bioText. Try this:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="76dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/conversation_list_border">

    <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/image"
        android:layout_width="62dp"
        android:layout_height="62dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="6dp"
        android:src="@drawable/default_color_1" />


    <TextView
        android:id="@+id/nameText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@+id/image"
        android:text="Tolgay Toklar"
        android:textColor="#727272"
        android:textSize="13sp"
        android:textStyle="bold" />

    <RelativeLayout
        android:id="@+id/unreadMessageBg"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="22dp"
        android:layout_marginTop="30dp"
        android:background="@drawable/konusmalar_chat_count_bg">

        <TextView
            android:id="@+id/unreadMessageCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:fontFamily="sans-serif"
            android:text="5"
            android:textColor="@color/white"
            android:textSize="12sp"
            android:textStyle="bold" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/nameText"
        android:layout_toEndOf="@id/image"
        android:layout_toRightOf="@id/image">

        <TextView
            android:id="@+id/bioText"
            android:layout_width="199dp"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="0dp"
            android:layout_marginStart="2dp"
            android:layout_marginTop="5dp"
            android:layout_toEndOf="@id/imageView22"
            android:layout_toRightOf="@id/imageView22"
            android:maxLines="1"
            android:layout_alignWithParentIfMissing="true"
            android:text="Selam Nasılsın?Selam Nasılsın?Selam Nasılsın?Selam Nasılsın?"
            android:textColor="#7A7A7A"
            android:textSize="15sp"
            android:textStyle="normal" />

        <ImageView
            android:id="@+id/imageView22"
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="3dp"
            android:layout_marginStart="0dp"
            android:layout_marginTop="6dp"
            app:srcCompat="@drawable/send_voice_record" />

    </RelativeLayout>

</RelativeLayout>

Put the imageView22 and bioText into another layout. The key point is to set android:layout_alignWithParentIfMissing="true" for bioText . In a RelativeLayout, that attribute would cause the view to apply the alignment specified by the attibutes to the parent instead of to the target view when the latter is GONE. For example, a view A that is aligned toRightOf another view (which we’ll call B) will go and align to the left edge of their parent if B is GONE.


Put imageView22 (I guess this is the play imageview) and bioText inside a relative layout, like:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/nameText"
    android:layout_alignStart="@+id/nameText"
    android:layout_alignLeft="@+id/nameText">

    <ImageView
        android:id="@+id/imageView22"
        android:layout_width="18dp"
        android:layout_height="18dp"
        android:layout_marginStart="0dp"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="6dp"
        android:layout_marginRight="3dp"
        app:srcCompat="@drawable/send_voice_record" />

    <TextView
        android:id="@+id/bioText"
        android:layout_width="199dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="2dp"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="5dp"
        android:layout_toEndOf="@+id/imageView22"
        android:layout_toRightOf="@+id/imageView22"
        android:maxLines="1"
        android:text="Selam Nasılsın?Selam Nasılsın?Selam Nasılsın?Selam Nasılsın?"
        android:textColor="#7A7A7A"
        android:textSize="15sp"
        android:textStyle="normal" />

</RelativeLayout>

When you make the imageview invisible, then the TextView will take the space that the imagview was previously. Of course you must fix other attributes.

in line 82 as follows (changing the first item's visibility as GONE at the bottom). addFab.setOnClickListener(new View.OnClickListener() { @  RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout….


Use ConstraintLayout instead of RelativeLayout. ConstraintLayout is basically a newer, better version of RelativeLayout, so the conversion shouldn't be too bad. Fortunately for you, when a view is GONE in ConstraintLayout, any view that was constrained to it behaves as though the target view is still there, just 0 size.

Here's your layout using ConstraintLayout. I've deleted all attributes other than ids and constraints, to make it more obvious what constraints you need to use.

<androidx.constraintlayout.widget.ConstraintLayout>

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/image"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>

    <TextView
        android:id="@+id/nameText"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@+id/image"/>

    <RelativeLayout
        android:id="@+id/unreadMessageBg"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <TextView ... />

    </RelativeLayout>

    <TextView
        android:id="@+id/bioText"
        app:layout_constraintTop_toBottomOf="@+id/nameText"
        app:layout_constraintStart_toEndOf="@+id/imageView22"/>

    <ImageView
        android:id="@+id/imageView22"
        app:layout_constraintTop_toBottomOf="@+id/nameText"
        app:layout_constraintStart_toStartOf="@+id/nameText"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Note that if you aren't using androidx, and are still using the old support libraries, the tag is this instead:

<android.support.constraint.ConstraintLayout>

If we use the editor to set visibility to Gone and Visible for the buttons, LinearLayout and RelativeLayout or we can just remove the tail view  there is a propery called VISIBILITY. It can be set a element on the layoutxml as below ( element can be a LinearLayout (viewgroup) or widgets like TextView,ImageView, etc ) - gone - Means the element will not be shown and its doesnt occupy space in the entire viewgroup. - visible - THe element is shown.


Using java class Using XML : use attribute android:visibility=”gone| visible|​invisible” Using java class : use What is the use of a relative layout in Android? There are two ways to set and change visibility of linear layout. 1. Using XML 2. Using java class Using XML : use attribute android:visibility=”gone| visible|invisible” Using java class : use findViewById to get linear layout id like R.id.linearl


RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling  Can't find relativeLayout id with findViewById. I am having an issue when I try to access the relativeLayout view object by id, it does not show up in auto-complete


You can place textview 2 and 3 in the LinearLayout and keep the linear layout below textview 1. First, make sure you have access to the View properties (i.e. View.INVISIBLE and View.GONE) by importing the object into the template. <data> <import type= "android.view.View" /> </data> Next, you can test for a condition (i.e. first name is null) and determine whether to show or hide the text view accordingly: