2016-01-12 10 views
7

Mam aplikację z układem koordynatora, który korzysta z przesuwanych kart i pagera widoku w układzie koordynatora. Próbuję umieścić działanie (listę) poniżej paska narzędzi. Próbowałem wielu różnych rzeczy, ale zawsze lista pokrywa się z paskiem narzędzi.Układ koordynatora, czynność pod paskiem narzędzi

Układ

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

Odpowiedz

2

spróbuj to:

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

usunąłem linearLayout i zastąpić go appBarLayout także dodał androida: layout_below w Framelayout

powodzenia

+0

nie mogę wykorzystać appbarlayout bo moja lista nie przewijać z viewpager tak miał aby to zmienić. – Carl

+0

ok, zachowaj Linearlayout, ale po prostu dodaj android: layout_below = "@ id/yourLinearLayoutID" w ramce FrameLayout i zobacz, czy to rozwiązało. – Netero

+0

Nie możesz użyć layout_below w CoordinatorLayout – Carl

2

Można zamienić CoordinatorLayout na LinearLayout (z androidem: orientation = "vertical").

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

Następnie mam problem z pływającym przyciskiem akcji – Carl

+0

Umieść ten nowy LinearLayout w RelativeLayout. I FAB na tym samym poziomie co LinearLayout (bezpośrednie dziecko z RelativeLayout) – Fundhor

11

Wystarczy dodać aplikację: layout_behavior = „@ ciąg/appbar_scrolling_view_behavior” do układu, który musi być pod paskiem narzędzi

Powiązane problemy