Reputation: 378
I have two view in a container like this.
[ContainerView
[view 1 (RelativeLayout)]
[view 2 (RelativeLayout)]
(Relative Layout)]
and id like to hide view1 whenever a certain variable is not given. i cant seem to find a solution to
Now i know this question has been asked a billion times, but all the solutions simply dont work for me...
Here are parts of the code:
layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:id="@+id/mainview">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="0dp"
android:layout_marginBottom="50dp"
android:elevation="4dp"
android:background="@android:color/white"
android:layout_alignParentTop="true"
android:id="@+id/header">
<TextView
android:id="@+id/headertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:text="Large Text"
android:padding="15dp"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="50dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/upperview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/lowerview"
android:layout_above="@+id/header">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:elevation="4dp"
android:id="@+id/vanisherView"
android:layout_centerHorizontal="true"
android:layout_margin="20dp">
<TextView
android:id="@+id/erklareung"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:background="@android:color/white"
android:padding="40dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="470dp"
android:id="@+id/lowerview"
android:padding="20dp"
android:background="@android:color/white"
android:elevation="4dp"
android:layout_above="@+id/bottom">
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_marginLeft="0dp"
android:id="@+id/bottom"
android:paddingTop="30dp"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"
android:textSize="30dp" />
<Button
android:id="@+id/nextButton"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="0.5"
android:text="Button"
android:textSize="30dp"
android:background="#009688"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
and what i tried sofar is
upperview.getLayoutParams().height = 0;
lowerview.getLayoutParams().height = 900;
mainview.invalidate()
upperview.setVisibility(View.INVISIBLE);
lowerview.getLayoutParams().height = 900;
Cheers
Jacobus
Upvotes: 0
Views: 76
Reputation: 800
I am not sure about what you have already tried in order to achieve this. For your reference, I am posting a sample code which is used to achieve the same output.
<?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="match_parent">
<RelativeLayout
android:id="@+id/rlView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Text Field in View 1" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/rlView1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Text Field in View 2" />
</RelativeLayout>
</RelativeLayout>
Please note that, you have to use rlView1.setVisiblity(View.GONE) in order to make rlView2 the same size as of parent.
Upvotes: 1