2017-11-22 1 views
0

Ich habe eine Aktivität mit einer Symbolleiste und einem framelayout, wo ich Fragmente injiziere. Negativer Rand Layout zum Überlagern des übergeordneten Layouts

Dies ist das Layout für diese Aktivität:

<android.support.v4.widget.DrawerLayout 
     android:id="@+id/drwDrawerRoot" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/background_main_selector" 
     android:theme="@style/AppTheme"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <include 
       android:id="@+id/viewMainToolbar" 
       layout="@layout/view_toolbar" /> 

     </LinearLayout> 

     <FrameLayout 
      android:id="@+id/frmDrawerContainer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="@dimen/toolbar_height" 
      android:clipChildren="false" 
      android:clipToPadding="false" 
      android:orientation="vertical" /> 

     <include 
      android:id="@+id/viewDrawer" 
      layout="@layout/view_drawer" 
      bind:name="@{name}"/> 

     <include 
      android:id="@+id/viewUserDrawer" 
      layout="@layout/view_user_drawer" 
      bind:name="@{name}"/> 

    </android.support.v4.widget.DrawerLayout> 

ich die framelayout mit einem Spielraum haben, so dass der Inhalt aus den Fragmenten nicht die Symbolleiste überlagern, aber ich gesetzt clipChildren und clipToPadding auf false wie pro einige andere Posts, die ich hier gesehen habe.

Auf einigen Fragmenten habe ich jedoch eine Ladeansicht, die ich auf dem ganzen Bildschirm belegen möchte.

Dies ist ein Beispiel-Fragment:

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:id="@+id/layout_main" 
      style="@style/Layout.FullScreen" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/layout_footer" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/textView7" 
       style="@style/Text.Header" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/login_header" /> 

      <EditText 
       android:id="@+id/edtMessage" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:elevation="1dp" 
       android:ems="10" 
       android:inputType="textMultiLine" /> 

      <Button 
       android:id="@+id/btnSend" 
       style="@style/Button.Primary" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/support_button" /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/layout_footer" 
      style="@style/Layout.FullScreen.Footer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/footerInfo" 
       style="@style/Text.White.Small.Centered" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/footer_info" /> 
     </LinearLayout> 

     <include 
      layout="@layout/view_loading" 
      android:visibility="invisible" 
      bind:loading="@{loading}" /> 

    </RelativeLayout> 

Ans dies ist der eingeschlossene Lade Ansicht, die ich mit negativen Rand gesetzt haben, in der Hoffnung es dem oberen Teil des Bildschirms bewegen würde:

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="-40dp" 
     android:background="@color/colorLoadingBackground" 
     android:clickable="true" 
     android:visibility="@{loading ? View.VISIBLE : View.GONE}"> 

    </FrameLayout> 

Fehle ich hier etwas?

Ist das machbar oder muss ich ändern, wie ich das mache?

Erläuterung: Das erste/root-Layout enthält eine Symbolleiste und das zweite Layout ist im Rahmenlayout des ersten enthalten. Dies bedeutet, dass der Inhalt des zweiten Layouts unterhalb der Symbolleiste beginnt. Ich möchte jedoch, dass das dritte Layout (ein Ladebildschirm, der in dem zweiten Layout enthalten ist) einen negativen Rand hat, so dass es den gesamten Bildschirm überlagert und nicht nur unterhalb der Symbolleiste beginnt.

Antwort

0

Sie müssen CoordinatorLayout verwenden, dann brauchen Sie keine negativen Ränder. hier sind die Beispielanlage u nach Ihrem Bedarf anpassen können

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay" 
      app:layout_behavior= "@string/appbar_scrolling_view_behavior"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:popupTheme="@style/AppTheme.PopupOverlay" 
       app:title="My App" /> 
     </android.support.design.widget.AppBarLayout> 

     <FrameLayout 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

     <!--include a full screen loading layout here and hide/show according to your need--> 
     <include layout="@layout/loading_layout/> 

    </android.support.design.widget.CoordinatorLayout> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:headerLayout="@layout/nav_header"/> 
    </android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout> 
+0

Es wäre toll, wenn Sie genau erklären, wie das funktioniert, ich bin nicht sicher, was dies zu erreichen, oder wenn dies würde auch mit getrennten arbeiten und enthalten Layouts. – BlunT

+0

Ersetzen Sie einfach Ihre Fragmente in Framelayout, die für Fragment-Container verwendet wird auch Ihre Frage nicht genug, um zu klären, was Sie brauchen? –

+0

Ich ersetzte die framelayouts und das Verhalten ist immer noch das gleiche. Wenn meine Frage nicht klar ist, werde ich versuchen zu klären. Das erste/root-Layout enthält eine Symbolleiste und das zweite Layout ist im Rahmenlayout des ersten enthalten. Dies bedeutet, dass der Inhalt des zweiten Layouts unterhalb der Symbolleiste beginnt. Ich möchte jedoch, dass das dritte Layout (ein Ladebildschirm, der in dem zweiten Layout enthalten ist) einen negativen Rand hat, so dass es den gesamten Bildschirm überlagert und nicht nur unterhalb der Symbolleiste beginnt. – BlunT

Verwandte Themen