2016-05-30 5 views
0

J'ai un problème avec la disposition du coordinateur. J'ai une barre d'outils d'activité dans appBarLayout avec le parent CoordinatorLayout (je veux rendre la barre d'outils cacheable) et je fragmente avec tablayout dans appBarLayout et viewPager. Voici XML de l'activitéMasquage de la mise en page à l'intérieur de la disposition du coordinateur, activité extérieure

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/gradient" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/toolbar_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways|snap" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

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

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

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

Et c'est le XML fragment

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/gradient" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      style="@style/MyCustomTabLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabGravity="fill"/> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewPager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

Pour l'instant, j'ai cette situation où la barre d'outils est quelque part. Si je change la disposition du coordinateur à l'intérieur de l'activité en disposition linéaire, j'obtiens la barre d'outils visible, mais comme vous pouvez l'imaginer sans option de masquage.

En fait, je dois jouer avec le coordinateur mise en page beaucoup: cacher et barre d'outils montrant dans quelques cas tels parallaxe et d'autres - https://github.com/Iamtodor/toolbars, de sorte que vous pouvez être sûr, j'ai un peu à comprendre comment cela fonctionne :)

aussi, j'avais wantch cette source: - https://github.com/codepath/android_guides/wiki/Handling-Scrolls-with-CoordinatorLayout - https://github.com/codepath/android_guides/wiki/Using-the-App-ToolBar#using-toolbar-as-actionbar - https://github.com/chrisbanes/cheesesquare

Mais il y a des exemples où tablayout existe à l'intérieur même appbarlayout avec la barre d'outils.

Comment puis-je résoudre ce problème?

+0

Toujours à la recherche de réponse – iamtodor

+0

UP, s'il vous plaît, est-il possible? – iamtodor

+0

J'ai un problème similaire. Je vais vous faire savoir ce que je trouve. – dazza5000

Répondre

0

Voici ce qui a fonctionné pour moi:

Fragment XML:

<android.support.design.widget.AppBarLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/app_bar_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:elevation="0dp"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_scrollFlags="scroll|enterAlways|snap" > 

     <include layout="@layout/include_time_line" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" /> 
    </android.support.v7.widget.Toolbar> 

    <android.support.design.widget.TabLayout 
     style="@style/TabLayout" 
     android:id="@+id/tabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="54dp" 
     android:layout_gravity="bottom" 
     android:background="@color/egg" 
     android:elevation="0dp" 
     app:tabGravity="fill" 
     app:tabMode="scrollable" 
     app:tabIndicatorColor="#fcd131" 
     app:tabPadding="0dp" 
     app:tabIndicatorHeight="4dp"/> 
</android.support.design.widget.AppBarLayout> 

<com.woot.woot.productbrowse.ui.ConfigurablePagingViewPager 
    android:id="@+id/viewPager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    /> 
<FrameLayout 
    android:id="@+id/selectByWeightKeyboard" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/weight_keyboard_container_height" 
    android:background="@color/keyboard" 
    android:clipToPadding="false" 
    android:elevation="16dp" 
    android:clickable="true" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

    <include layout="@layout/add_product_by_weight_keyboard" /> 
</FrameLayout> 

XML d'activité:

<FrameLayout 
     android:id="@+id/contentFrame" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <FrameLayout 
     android:id="@+id/layout_done_button" 
     android:visibility="gone" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:elevation="8dp" 
     tools:visibility="visible" 
     android:background="@color/ice"> 

     <Button 
      android:id="@+id/button_done" 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/button_height" 
      android:layout_marginRight="@dimen/button_done_horizontal_margin" 
      android:layout_marginLeft="@dimen/button_done_horizontal_margin" 
      android:layout_marginTop="@dimen/activity_horizontal_margin" 
      android:layout_marginBottom="@dimen/activity_horizontal_margin" 
      android:background="@drawable/rounded_green_button" 
      android:text="@string/done" 
      android:textSize="@dimen/button_text_size" 
      android:textAllCaps="true" 
      android:textColor="@color/egg" /> 
    </FrameLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/navigation" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:contentDescription="@string/drawer_content_description" 
    app:menu="@menu/menu_navigation_product_browse" />