10

Spotkałem wiele problemów związanych z moim problemem, ale nikt nie znalazł pożądanego zachowania, którego szukam.AppBarLayout + TabLayout + CollapsingToolbarLayout + SwipeToRefresh

Chcę wyświetlać pagery z zakładkami i paskiem aplikacji, gdy zawarte fragmenty są przewijane i przewijane (w kierunku dołu), chcę, aby pasek aplikacji znikał, ale pozostaw karty, gdy przewijam w kierunku do góry, aby ponownie się wyłapać . niektóre z tych fragmentów zawierają układ SwipeToRefresh (czasami powoduje to problemy). Próbowałem wielu konfiguracji, które zawsze pozostawiały coś nie tak.

na razie nie mam wpływu zawaleniem (to zawsze ukryty)

<?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=".MainPagerActivity"> 

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

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

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|enterAlways"> 


      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:tabGravity="fill" 
       app:tabIndicatorHeight="6dp" 
       app:tabMode="fixed" /> 

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


    <android.support.v4.view.ViewPager 
     android:id="@+id/main_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/app_bar_layout" 
     tools:context=".MainPagerActivity" 

     /> 

</RelativeLayout> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_menu_edit" /> 

i jeden z moich fragmentu (przewijanie jednym):

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:wheel="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.m360learning.app.fragment.MainPagerNewsFeed"> 


    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipeRefreshLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

      <com.pnikosis.materialishprogress.ProgressWheel 
       android:id="@+id/progress_wheel" 
       android:layout_width="80dp" 
       android:layout_height="80dp" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       wheel:matProg_barColor="#5588FF" 
       wheel:matProg_progressIndeterminate="true" /> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recycler" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical" /> 

     </RelativeLayout> 

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

</FrameLayout> 

I don nie wiem dokładnie, co zrobiłem, ale od czasu, gdy zacząłem pisać to pytanie refreshLayout uniemożliwiłoby mojej liście odejście (odświeża się zamiast tego) ..

Dziękujemy

------ Korekta!

dzięki Sir Ellie Zou, obecnie współpracuje z tym xml:

<?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=".MainPagerActivity"> 


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




      <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_collapseMode="pin" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:tabGravity="fill" 
       app:tabIndicatorHeight="6dp" 
       app:tabMode="fixed" /> 

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


    <android.support.v4.view.ViewPager 
     android:id="@+id/main_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".MainPagerActivity" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 

     /> 


    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_menu_edit" /> 


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

i układ fragment:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:wheel="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.m360learning.app.fragment.MainPagerNewsFeed"> 


    <com.pnikosis.materialishprogress.ProgressWheel 
     android:id="@+id/progress_wheel" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_gravity="center" 
     wheel:matProg_barColor="#5588FF" 
     wheel:matProg_progressIndeterminate="true" /> 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipeRefreshLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycler" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" /> 


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


</FrameLayout> 

Odpowiedz

11

Jeśli nie ma efektu paralaksy, nie trzeba używać CollapsingToolbarLayout.

Najważniejszym konfiguracja:

na pasku narzędzi, ustaw app:layout_scrollFlags="scroll|enterAlways".

W ViewPager, ustaw app:layout_behavior="@string/appbar_scrolling_view_behavior".

i układ powinien wyglądać następująco:

<android.support.design.widget.CoordinatorLayout> 

    <android.support.design.widget.AppBarLayout> 

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

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

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

    <android.support.v4.view.ViewPager/> 

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

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

Move ProgressWheel ze swojego SwipeRefreshLayout aby naprawić problem, który SwipeRefreshLayout nie może odświeżyć.

+0

Świetnie! Aktualizuję swój wpis, dziękuję bardzo! –

+0

Oups przepraszam, nie zauważyłem, ale swipeToRefresh jest źle złamany, jakiś pomysł? –

+0

spróbuj przenieść 'ProgressWheel' z' SwipeRefreshLayout' –

Powiązane problemy