2016-03-31 28 views
0

Ich habe zwei Sicht in einem Container wie folgt.Die Größe eines Layouts ändern

[ContainerView  
[view 1 (RelativeLayout)]  
[view 2 (RelativeLayout)]  
(Relative Layout)] 

und id gerne view1 ausblenden, wenn eine bestimmte Variable nicht gegeben ist. Ich kann nicht scheinen, um eine Lösung zu

  1. hide view1 vollständig
  2. resive Ansicht2 finden Sie die gesamte ContainerView

Nun ich diese Frage wissen zu füllen hat eine Milliarde Mal gefragt worden, aber alle Lösungen einfach arbeiten nicht für mich ...

Hier sind Teile des Codes:

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> 

und was ich versuchte sofar heißt

  1. upperview.getLayoutParams().height = 0; lowerview.getLayoutParams().height = 900; mainview.invalidate()
  2. gleiche mit requestLayout
  3. ein neues RelativeLayout für die untere Layout mit statischen Größen
  4. upperview.setVisibility(View.INVISIBLE); lowerview.getLayoutParams().height = 900;

Beifall Schaffung

Jacobus

+0

VIew1.setVisiblity (VISIBLE.GONE) – Manifest

+0

@VarunKumar getLayoutParams(). Height = 0/900 und ähnliche Layout-Änderungen, im Grunde die einzige Lösung, die für andere Fragen vorgeschlagen wird immer – PlatinTato

+0

Code veröffentlichen. Bearbeiten Sie die obige Frage und geben Sie Ihren Code ein, den Sie bisher ausprobiert haben. –

Antwort

1

Ich bin mir nicht sicher, was Sie bereits versucht haben, um dies zu erreichen. Als Referenz veröffentliche ich einen Beispielcode, mit dem die gleiche Ausgabe erreicht wird.

<?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> 

Bitte beachten Sie, dass Sie rlView1.setVisiblity (View.GONE) verwenden, um zu machen rlView2 die gleiche Größe wie die Eltern.

+0

Ich habe gerade meine Xml gepostet. Es tut mir leid für diese Unannehmlichkeit: D ich brauche die untere Ansicht von Anfang an von statischer Größe – PlatinTato

+0

Ich habe gerade versucht, Ihre Lösung scheint es auch nicht zu arbeiten. Ich machte rlView der statischen Größe und tat das Layout_below = rlView1. Ich rufe dann setVisibility (View.INVISIBLE) auf, aber es versteckt es nur, und die Größe der anderen Ansichten ändert sich nicht. BEARBEITEN View.GONE macht den Trick ... ich denke, ich bin nur zurückgeblieben – PlatinTato

+0

Oh ja mein Fehler, statt VISIBLE.GONE sollte View.GONE sein –

Verwandte Themen