Coleen
Coleen

Reputation: 124

Make visible single View in RelativeLayout

I have a RelativeLayout which contains a LinearLayout containing 2 buttons. I would like to make those buttons visible without making the whole RelativeLayout or LinearLayout visible. While debugging, the button's getVisibility reports visible and getLocationOnScreen returns the correct placement but I can't see them. Here is my xml

<RelativeLayout
    android:id="@+id/edit_div_element"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:padding="20dp"
    android:background="@drawable/full_popup_element"
    android:layout_alignParentBottom="true"
    android:visibility="gone"
    android:layout_centerVertical="true"
    android:clickable="false">

    <ImageView
        android:id="@+id/close_edit"
        android:src="@drawable/view_edge_promotion_close_icon"
        android:layout_gravity="right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:tint="@color/uniform_style_blue"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="-10dp"/>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/popup_name_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/close_edit"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/popup_name_label"
            android:text="@string/popup_name_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textStyle="bold"
            android:textSize="@dimen/font_size_fixed_16" />

        <EditText
            android:id="@+id/popup_name"
            android:hint=""
            android:layout_width="170dp"
            android:layout_height="wrap_content"
            android:inputType="textCapWords"
            android:singleLine="true"
            android:textSize="18sp"
            android:layout_marginLeft="15dp"
            android:paddingBottom="2dp"
            android:paddingLeft="@dimen/marginSmall" />

    </LinearLayout>

    <TextView
        android:id="@+id/popup_assignment_label"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/edit_assignment_label"
        android:layout_below="@id/popup_name_container"
        android:layout_marginTop="20dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:orientation="horizontal"
        android:layout_below="@id/popup_assignment_label"
        android:gravity="bottom"
        >

      <android.support.v7.widget.RecyclerView
                android:id="@+id/popup_assignment_recycler"
                android:layout_width="180dp"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:clickable="false"/>


        <Button
            android:id="@+id/btn_1"
            android:text="@string/clear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/popup_assignment_recycler"
            android:layout_alignParentRight="true"
            android:gravity="bottom"
            android:padding="6dp"
            android:maxLines="1"
            android:background="@color/uniform_style_blue"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="18dp"
            />
        <Button
            android:id="@+id/btn_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/btn_1"
            android:layout_alignParentRight="true"
            android:gravity="bottom"
            android:padding="6dp"
            android:maxLines="1"
            android:background="@color/uniform_style_blue"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="9dp"
            />
    </LinearLayout>

</RelativeLayout>

I'm setting visibility with

Button mBtn1 = findViewById(R.id.btn_1);
mBtn1.setVisibility(View.VISIBLE);
Button mBtn2 = findViewById(R.id.btn_2);
mBtn2.setVisibility(View.VISIBLE);

I've also tried defining the RelativeLayout's visibility as INVISIBLE in the xml, still no luck.

Is it possible to just show the buttons? I'm stumped, so any help is appreciated!

Upvotes: 0

Views: 467

Answers (1)

Hanna
Hanna

Reputation: 71

You have buttons placed inside the layout. If the whole parent is invisible, all the child views are invisible too. If you want to show only buttons, you have to make your relative layout visible, your linear layout visible, and then make your buttons visible. You can also hide all other content of your layout (make invisible) if you do not wanna show it.

Consider parent-child views as boxes. Your buttons - are small boxes, which are placed inside of other, bigger box, which is parent, linear layout. You cannot open small boxes without opening the large (parent) box first.

Upvotes: 1

Related Questions