Reputation: 13985
I have a RelativeLayout, call it my_rel
, with a number of children. I use the include
tag to include the my_rel
into another layout. Anyway, When I set my_rel
's visibility to GONE, the children of my_rel
are still visible? How do I prevent that from happening?
Here is the larger/envelop view:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0F1F3"
tools:context=".CookingFiest" >
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="84dp"
android:background="#CCCCCC" />
<View
android:layout_width="4dp"
android:layout_height="fill_parent"
android:layout_marginLeft="85dp"
android:background="#FFFFFFFF" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="89dp"
android:background="#CCCCCC" />
<ScrollView
android:id="@+id/my_scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dip"
android:isScrollContainer="false" >
<LinearLayout
android:id="@+id/timeline_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<com.nothing.noevil.widget.HorizontalListView
android:id="@+id/cool_stuff"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_above="@id/cool_stuff"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" />
<include
android:id="@+id/appliance"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
layout="@layout/kitchen" />
<RelativeLayout
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:background="#00000000"
android:clickable="true" >
<ImageView
android:id="@+id/cook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:onClick="oncookClicked"
android:src="@drawable/match_here" />
<ImageView
android:id="@+id/shoe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/cook"
android:clickable="true"
android:onClick="onshoeClicked"
android:src="@drawable/shoe" />
<ImageView
android:id="@+id/pencil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/cook"
android:clickable="true"
android:onClick="onRiverClicked"
android:src="@drawable/pencil" />
</RelativeLayout>
</RelativeLayout>
Here is the nested/included view:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:clickable="true"
android:visibility="gone"
android:onClick="mangoes" >
<!-- Backgrounds -->
<ImageView
android:id="@+id/bkg_1"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:background="#e8edf3" />
<ImageView
android:id="@+id/bkg_2"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_alignParentBottom="true"
android:background="#f6f6f6" />
<!-- Two timers -->
<TextView
android:id="@+id/orange"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/bkg_1"
android:layout_alignParentLeft="true"
android:layout_alignTop="@id/bkg_1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="2dp"
android:gravity="center_vertical"
android:text=""
android:textColor="#1083f0"
android:textSize="12sp" />
<TextView
android:id="@+id/apple"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/bkg_2"
android:layout_alignParentLeft="true"
android:layout_alignTop="@id/bkg_2"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text=""
android:textColor="#555555"
android:textSize="12sp"
android:textStyle="bold" />
<!-- Spot icon -->
<ImageView
android:id="@+id/veggies"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/bkg_2"
android:layout_alignTop="@id/bkg_1"
android:layout_marginBottom="2dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/orange"
android:background="#000000"
android:padding="10dp"
android:src="@drawable/img1" />
<!-- Descriptions -->
<TextView
android:id="@+id/sheo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/bkg_1"
android:layout_alignTop="@id/bkg_1"
android:layout_marginBottom="3dp"
android:layout_toRightOf="@id/veggies"
android:gravity="center_vertical"
android:text=""
android:textColor="#1083f0"
android:textSize="12sp" />
<TextView
android:id="@+id/chalks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/bkg_2"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/bkg_2"
android:layout_marginTop="3dp"
android:layout_toRightOf="@id/veggies"
android:gravity="center_vertical"
android:text=""
android:textColor="#555555"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
If I set GONE within xml it's fine. But if I set gone programmatically, it's ignored.
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
kich = (RelativeLayout) mInflater.inflate(R.layout.kitchen, null);
kich.setVisibility(View.GONE);
Upvotes: 2
Views: 7951
Reputation: 13985
I solve the problem by instantiating as
kich = (RelativeLayout) findViewById(R.id.appliance)
The id is in the include tag
<include
android:id="@+id/appliance"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
layout="@layout/kitchen" />
Upvotes: 0
Reputation: 1686
It's weird when you inflate the include
into your main_view like you did.
Try this, inside the R.layout.kitchen
xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/kitchen_parent" <!-- HERE -->
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:clickable="true"
android:onClick="mangoes"
android:visibility="gone" >
And inside your Activity
:
ViewStub stub = (ViewStub) findViewById(R.id.appliance);
stub.inflate();
RelativeLayout kitchen_parent = findViewById(R.id.kitchen_parent);
kitchen_parent.setVisibility(View.GONE);
Hope this helps.
Upvotes: 5