0

Wenn ich view.setVisibility (View.VISIBLE) auf der RelativeLayout @ + id/saveCancelBar unten aufrufen, deckt es einen Teil der FrameLayout ab. Ich möchte das FrameLayout verkleinern, um das RelativeLayout zu passen. Wenn ich alles in einem Linearlayout setzen eher als ein RelativeLayout, die SaveCancelBar zeigt verschiebt einfach alles nach oben und bewegt sich ein Teil der Toolbar außerhalb des BildschirmsWie wird die Größe von Kind von RelativeLayout geändert, wenn ein anderes Kind sichtbar gemacht wird?

<RelativeLayout 
    android:id="@+id/content_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:gravity="center|bottom"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/colorPrimary" 
     android:elevation="4dp" 
     android:layout_alignParentTop="true" 
     android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

    <LinearLayout 
     android:id="@+id/content_view_panes" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar" 
     android:orientation="horizontal" 
     android:gravity="bottom"> 

     <WebView 
      android:id="@+id/mainWebView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:visibility="gone" /> 

     <FrameLayout 
      android:id="@+id/listContainer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:background="@color/colorPrimaryDark" 
     android:layout_below="@+id/content_view_panes" 
     android:visibility="gone" 
     android:id="@+id/saveCancelBar"> 
     <Button 
      android:id="@+id/editorCancelButton" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="@string/editor_cancel" 
      android:textColor="@color/white" 
      android:layout_alignParentLeft="true" 
      android:background="@color/colorPrimaryDark"/> 
     <Button 
      android:id="@+id/editorSaveButton" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="@string/editor_save" 
      android:textColor="@color/white" 
      android:layout_alignParentRight="true" 
      android:background="@color/colorPrimaryDark"/> 
    </RelativeLayout> 
</RelativeLayout> 

Antwort

0

Sie brauchen zwei Dinge zu tun.

Erstens die FrameLayout mit id listContainer nicht vertikal entziehen, weil es Eltern haben layout_height Set match_parent. Sie sollten das übergeordnete Objekt content_view_panes und das saveCancelBar in ein LinearLayout mit vertikaler Ausrichtung einbinden und das layout_height auf 0dp setzen, wobei layout_width auf 1 festgelegt werden soll. Für ein Kind eines LinearLayouts sagt dies, dass es den verbleibenden Platz ausfüllt. Sie müssen die Breite oder Höhe von listContainer nicht ändern, da die Größe basierend auf dem übergeordneten Element geändert wird.

Wenn Sie nun die Sichtbarkeit von saveCancelBar ändern, wird die content_view_panes und damit listContainer ihre Höhe angepasst haben.

Z. B .:

<RelativeLayout 
android:id="@+id/content_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:gravity="center|bottom"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@color/colorPrimary" 
    android:elevation="4dp" 
    android:layout_alignParentTop="true" 
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/toolbar" 
    android:orientation="vertical"> 
    <LinearLayout 
     android:id="@+id/content_view_panes" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal"> 

     <WebView 
      android:id="@+id/mainWebView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:visibility="gone" /> 

     <FrameLayout 
      android:id="@+id/listContainer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:background="@color/colorPrimaryDark" 
     android:layout_below="@+id/content_view_panes" 
     android:visibility="gone" 
     android:id="@+id/saveCancelBar"> 
     <Button 
      android:id="@+id/editorCancelButton" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="@string/editor_cancel" 
      android:textColor="@color/white" 
      android:layout_alignParentLeft="true" 
      android:background="@color/colorPrimaryDark"/> 
     <Button 
      android:id="@+id/editorSaveButton" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="@string/editor_save" 
      android:textColor="@color/white" 
      android:layout_alignParentRight="true" 
      android:background="@color/colorPrimaryDark"/> 
    </RelativeLayout> 
</LinearLayout> 

+0

dies nicht funktioniert. Ist es wichtig, wenn ich die Sichtbarkeit festlege? Ich nehme an, dass es in onCreateView() sein sollte? Ist es wichtig, dass die Höhe des LinearLayouts mit der ID 'content_view_panes' auf" Match_parent "gesetzt ist? Wenn ich nach wrap_content wähle, bekomme ich einen Fehler, wenn ich ein WebView in ein Elternteil mit height wrap_content setze. – trpnd

+0

Mein Fehler, ich hatte nicht bemerkt, dass die LinearLayout 'content_view_panes' horizontale Ausrichtung ist. Ich habe die Antwort aktualisiert und funktionierenden, getesteten Code hinzugefügt –

Verwandte Themen