2016-06-29 20 views
-1

: Ich bin in Material-Design, ich bin nicht in der Lage Symbolleiste zu verbergen, wenn list.For weitere Informationen Scrollen ich meinen Code teilen bin unten gegeben:ausblenden Symbolleiste beim Scrollen recyclerview

1.Allg Layout für App

<?xml version="1.0" encoding="utf-8"?> 

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/background_light"> 

     <RelativeLayout 
      android:id="@+id/main_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 
       <!-- <include layout="@layout/custom_toolbar" />--> 
       <RelativeLayout 
        android:id="@+id/toolbarContainer" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

        <android.support.design.widget.AppBarLayout 
         android:id="@+id/appbar" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:fitsSystemWindows="true" 
         android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 


         <android.support.v7.widget.Toolbar 
          android:id="@+id/customToolbar" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:background="@color/colorPrimary" 
          android:minHeight="?attr/actionBarSize" 
          android:textColorPrimary="@color/textColorPrimary" 
          app:colorButtonNormal="@android:color/white" 
          app:colorControlHighlight="?attr/colorPrimaryDark" 
          app:colorControlNormal="?android:attr/textColorPrimary" 
          app:layout_scrollFlags="scroll|enterAlways" 
          app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
          app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

          <TextView 
           android:id="@+id/actionbar_title" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:gravity="center_horizontal" 
           android:textColor="@color/colorPrimaryDark" 
           android:textSize="@dimen/action_bar_title_text_size" 
           android:textStyle="bold" /> 

          <ImageView 
           android:id="@+id/toolbar_logo" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_gravity="left" 
           android:src="@drawable/btn_check_on" 
           android:visibility="gone" /> 
         </android.support.v7.widget.Toolbar> 
        </android.support.design.widget.AppBarLayout> 

        <ImageView 
         android:id="@+id/drawerIcon" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerHorizontal="true" 
         android:src="@drawable/img_drawer_logo" /> 

       </RelativeLayout> 

       <android.support.design.widget.TabLayout 
        android:id="@+id/tabs" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:visibility="gone" 
        app:tabGravity="fill" 
        app:tabMaxWidth="0dp" 
        app:tabMode="fixed" 
        app:tabSelectedTextColor="@color/orange_100" 
        app:tabTextColor="@color/grey" /> 

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


       <include layout="@layout/horizontal_line" /> 
       <!-- As the main content view, the view below consumes the entire 
        space available using match_parent in both dimensions. --> 
       <FrameLayout 
        android:id="@+id/content_frame" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginTop="@dimen/baseline" 
        app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
      </LinearLayout> 

      <moebel.de.app.ui.view.MaterialSearchView 
       android:id="@+id/search_view" 
       style="@style/MaterialSearchViewStyle" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

      <moebel.de.app.ui.view.ShopFinderSearchView 
       android:id="@+id/shopfinder_search_view" 
       style="@style/ShopFinderSearchViewStyle" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

      <LinearLayout 
       android:id="@+id/layout_progressbar" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:background="@color/transparentColor" 
       android:gravity="center" 
       android:visibility="visible"> 

       <ProgressBar 
        android:id="@+id/progressBar1" 
        style="@android:style/Widget.ProgressBar.Large" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
      </LinearLayout> 

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

    <RelativeLayout 
     android:id="@+id/drawer_left" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/drawerListBackground" 
     android:clickable="true"> 

     <ListView 
      android:id="@+id/navigation_list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:choiceMode="singleChoice" 
      android:divider="@null" 
      android:listSelector="@drawable/drawer_list_selector" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:src="@drawable/img_drawer_logo" /> 

    </RelativeLayout> 

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

2.Run Zeit Hinzufügen Fragment mit diesem Layout:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:clickable="true" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:id="@+id/filterLayout" 
     android:layout_width="match_parent" 
     android:layout_height="44dp" 
     android:baselineAligned="false" 
     android:orientation="horizontal" 
     android:padding="@dimen/baseline"> 

     <LinearLayout 
      android:id="@+id/categoryLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginEnd="2dp" 
      android:layout_marginRight="2dp" 
      android:layout_weight="0.5" 
      android:background="@color/grey_100" 
      android:gravity="center" 
      android:orientation="horizontal"> 

      <ImageView 
       android:id="@+id/dotImage" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="2dp" 
       android:drawablePadding="@dimen/baseline" 
       android:src="@drawable/dot_image" 
       android:visibility="gone" /> 

      <TextView 
       android:id="@+id/categoryText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:drawableEnd="@drawable/ic_filter_arrow" 
       android:drawablePadding="@dimen/baseline" 
       android:drawableRight="@drawable/ic_filter_arrow" 
       android:text="@string/fragment_products_button_category" 
       android:textColor="@color/grey_400" 
       android:textSize="18sp" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/filter" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="2dp" 
      android:layout_marginStart="2dp" 
      android:layout_weight="0.5" 
      android:background="@color/grey_100" 
      android:gravity="center" 
      android:orientation="horizontal"> 

      <ImageView 
       android:id="@+id/filterDotImage" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="2dp" 
       android:drawablePadding="@dimen/baseline" 
       android:src="@drawable/dot_image" 
       android:visibility="gone" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:drawableEnd="@drawable/ic_filter_arrow" 
       android:drawablePadding="@dimen/baseline" 
       android:drawableRight="@drawable/ic_filter_arrow" 
       android:text="@string/fragment_products_button_filter" 
       android:textColor="@color/grey_400" 
       android:textSize="18sp" /> 
     </LinearLayout> 
    </LinearLayout> 

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

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

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/product_grid_view" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:overScrollMode="never" 
       android:scrollbars="vertical" 
       tools:listitem="@layout/product_grid_item" /> 


      <TextView 
       android:id="@+id/listEmpty" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:text="Du hast keine Produkte auf Deinem Merkzettel" 
       android:visibility="gone" /> 




      <LinearLayout 
       android:id="@+id/layout_progressbar" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:background="@color/transparentColor" 
       android:gravity="center" 
       android:visibility="visible"> 

       <ProgressBar 
        android:id="@+id/progressBar1" 
        style="@android:style/Widget.ProgressBar.Large" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
      </LinearLayout> 


      <View 
       android:id="@+id/transparent_view" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/transparentColor" 
       android:visibility="gone" 
       /> 

     </RelativeLayout> 

     <LinearLayout 
      android:id="@+id/layout_bottomProgressBar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="0.9" 
      android:background="@color/progressbarBackground" 
      android:gravity="center" 
      android:visibility="gone"> 

      <ProgressBar 
       style="@android:style/Widget.ProgressBar.Small" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 

    </LinearLayout> 

</LinearLayout> 

Bitte mir helfen, die Lösung .i steckte in diesem Problem nicht wissen, um herauszufinden, was in diesem Code falsch ist.

+0

Mögliche Duplikate von [Android Lollipop Toolbar: wie zu verbergen/s wie die toolbar beim scrollen?] (http://stackoverflow.com/questions/26539623/android-lollipop-toolbar-how-to-hide-show-the-toolbar-while-scrolling) – SaravInfern

Antwort

0

Fügen Sie diese:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

zu Ihrem RecyclerView-Tag und dem Root-Tag des Fragments.

+0

ich habe layout_behavior nach ihnen hinzugefügt aber es funktioniert nicht. –

0

Sie können so etwas wie dieses

public abstract class HidingScrollListener extends RecyclerView.OnScrollListener { 
private static final int HIDE_THRESHOLD = 20; 
private int scrolledDistance = 0; 
private boolean controlsVisible = true; 

@Override 
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
super.onScrolled(recyclerView, dx, dy); 

if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) { 
    onHide(); 
    controlsVisible = false; 
    scrolledDistance = 0; 
} else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) { 
    onShow(); 
    controlsVisible = true; 
    scrolledDistance = 0; 
} 

if((controlsVisible && dy>0) || (!controlsVisible && dy<0)) { 
    scrolledDistance += dy; 
} 
} 

public abstract void onHide(); 
public abstract void onShow(); 

} 

tun und dann diese Zuhörer auf Ihre RecyclerView

recyclerView.setOnScrollListener(new HidingScrollListener() { 
@Override 
public void onHide() { 
    hideViews(); 
} 
@Override 
public void onShow() { 
    showViews(); 
} 
}); 

In hideViews() Methode hinzufügen Sie Ihre Symbolleiste
mToolbar.animate().translationY(-mToolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2));

In showViews() Verfahren verstecken Sie können Ihre Symbolleisteanzeigen 210 mToolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2));

prüfen diese link out für die komplette Tutorial

0

Wenn Sie diese verwenden:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

Ihrer Symbolleiste Scrollen Sie bitte Ihr Layout neu zu gestalten.

layout_behavior nur wirksam, wenn AppBarLayout sind Kinder unter CoordinatorLayout

wie folgt aus:

<android.support.design.widget.CoordinatorLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/background_light"> 

      <android.support.design.widget.AppBarLayout 
        android:id="@+id/appbar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:fitsSystemWindows="true" 
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
      </android.support.design.widget.AppBarLayout> 
</android.support.design.widget.CoordinatorLayout> 
0

Nach R & D fand ich, dass AppBarLayout muss die direkte Kind CoordinatorLayout werden, so wird meine korrigierten Code unten

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

    <RelativeLayout 
     android:id="@+id/main_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

      <android.support.design.widget.CoordinatorLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/background_light"> 

       <android.support.design.widget.AppBarLayout 
        android:id="@+id/appbar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:fitsSystemWindows="true" 
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
        app:elevation="0dp"> 

         <android.support.v7.widget.Toolbar 
          android:id="@+id/customToolbar" 
          android:layout_width="match_parent" 
          android:layout_height="?attr/actionBarSize" 
          android:background="?attr/colorPrimary" 
          android:textColorPrimary="@color/textColorPrimary" 
          app:layout_scrollFlags="scroll|enterAlways"              
          app:colorButtonNormal="@android:color/white" 
          app:colorControlHighlight="?attr/colorPrimaryDark" 
          app:colorControlNormal="?       android:attr/textColorPrimary" 
          app:layout_scrollFlags="scroll|enterAlways" 
          app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
          app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

          <TextView 
           android:id="@+id/actionbar_title" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:gravity="center_horizontal" 
           android:textColor="@color/colorPrimaryDark" 
           android:textSize="@dimen/action_bar_title_text_size" 
           android:textStyle="bold" /> 

          <ImageView 
           android:id="@+id/toolbar_logo" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_gravity="left" 
           android:src="@drawable/btn_check_on" 
           android:visibility="gone" /> 

         </android.support.v7.widget.Toolbar> 


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

        <android.support.design.widget.TabLayout 
         android:id="@+id/tabs" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:visibility="gone" 
         app:tabGravity="fill" 
         app:tabMaxWidth="0dp" 
         app:tabMode="fixed" 
         app:tabSelectedTextColor="@color/orange_100" 
         app:tabTextColor="@color/grey" /> 
       </android.support.design.widget.AppBarLayout> 

       <FrameLayout 
        android:id="@+id/content_frame" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginTop="@dimen/baseline" 
        app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

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

     <moebel.de.app.ui.view.MaterialSearchView 
      android:id="@+id/search_view" 
      style="@style/MaterialSearchViewStyle" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <moebel.de.app.ui.view.ShopFinderSearchView 
      android:id="@+id/shopfinder_search_view" 
      style="@style/ShopFinderSearchViewStyle" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <LinearLayout 
      android:id="@+id/layout_progressbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:background="@color/transparentColor" 
      android:gravity="center" 
      android:visibility="visible"> 

      <ProgressBar 
       android:id="@+id/progressBar1" 
       style="@android:style/Widget.ProgressBar.Large" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 

    </RelativeLayout> 


    <RelativeLayout 
     android:id="@+id/drawer_left" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/drawerListBackground" 
     android:clickable="true"> 

     <ListView 
      android:id="@+id/navigation_list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:choiceMode="singleChoice" 
      android:divider="@null" 
      android:listSelector="@drawable/drawer_list_selector" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:src="@drawable/img_drawer_logo" /> 

    </RelativeLayout> 

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