2016-01-12 16 views
7

Ho un'app con un layout di coordinatore che utilizza schede scorrevoli e un cercapersone di visualizzazione in un layout di coordinatore. Sto tentando di inserire un'attività (elenco) sotto la barra degli strumenti. Ho provato un certo numero di cose diverse ma sempre la lista si sovrappone alla barra degli strumenti.Layout del coordinatore, attività sotto la barra degli strumenti

layout

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    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" android:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      android:fitsSystemWindows="true" 
      android:minHeight="?attr/actionBarSize" 
      android:padding="2dp" 
      app:titleMarginStart="20dp" 
      android:theme="@style/AppTheme.AppBarOverlay"/> 

     <com.passwordstore.utility.SlidingTabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/colorPrimary" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="4dp" 
      android:background="@android:color/white" 
      android:foreground="@drawable/shadow"/> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 
     </android.support.v4.view.ViewPager> 

    </LinearLayout> 

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

     <include layout="@layout/activity_password_list" /> 

    </FrameLayout> 

    <android.support.design.widget.FloatingActionButton android:id="@+id/fabNew" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" android:src="@drawable/ic_add_white_24dp" 
     app:layout_anchor="@+id/pager" 
     app:layout_anchorGravity="bottom|right|end"/> 

</android.support.design.widget.CoordinatorLayout> 

risposta

2

si prega di provare questo:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    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" android:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      android:fitsSystemWindows="true" 
      android:minHeight="?attr/actionBarSize" 
      android:padding="2dp" 
      app:titleMarginStart="20dp" 
      android:theme="@style/AppTheme.AppBarOverlay"/> 

     <com.passwordstore.utility.SlidingTabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/colorPrimary" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="4dp" 
      android:background="@android:color/white" 
      android:foreground="@drawable/shadow"/> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 
     </android.support.v4.view.ViewPager> 

    </android.support.design.widget.AppBarLayout> 

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

     <include layout="@layout/activity_password_list" /> 

    </FrameLayout> 

    <android.support.design.widget.FloatingActionButton android:id="@+id/fabNew" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" android:src="@drawable/ic_add_white_24dp" 
     app:layout_anchor="@+id/pager" 
     app:layout_anchorGravity="bottom|right|end"/> 

</android.support.design.widget.CoordinatorLayout> 

ho rimosso LinearLayout e sostituirlo con appBarLayout anche, ha aggiunto Android: layout_below nel vostro Framelayout

buona fortuna

+0

non posso usare appbarlayout perché la mia lista non scorre con il viewpager così avuto per cambiarlo. – Carl

+0

ok, mantieni il tuo Linearlayout, ma aggiungi Android: layout_below = "@ id/yourLinearLayoutID" nel tuo FrameLayout e verifica se è stato risolto. – Netero

+0

Non puoi usare layout_below in un CoordinatorLayout – Carl

2

È possibile sostituire il CoordinatorLayout con un LinearLayout (con android: orientation = "vertical").

<RelativeLayout> 
    <LinearLayout> (replaces the coordinator layout> 
     <AppBarLayout/> 
     <FrameLayout/> 
    </LinearLayout> 
    <FloatingActionButton/> 
</RelativeLayout> 
+0

Quindi ho problemi con il pulsante di azione fluttuante – Carl

+0

Inserire questo nuovo LinearLayout in un RelativeLayout. E il FAB allo stesso livello del LinearLayout (figlio diretto del RelativeLayout) – Fundhor

11

Basta aggiungere app: layout_behavior = "@ string/appbar_scrolling_view_behavior" per il layout che ha bisogno di essere sotto la barra degli strumenti

Problemi correlati