7

Còn nhiều vấn đề khác khi sử dụng CoordinatorLayout và AppBarLayout.CoordinatorLayout/AppBarLayout ExpandableListXem màn hình tắt hiển thị

Tôi đang cố gắng đạt được chức năng cơ bản của việc cuộn màn hình Thanh công cụ khi cuộn xuống và quay lại màn hình khi cuộn lên.

Tuy nhiên, thiết lập hiện tại của tôi đang hiển thị sự cố: Không chỉ Thanh công cụ không cuộn ra, ListView dường như đang hiển thị màn hình ở dưới cùng. Nó gần như là nó được bù đắp bởi chiều cao AppBarLayout.

Đây là một gif mô tả vấn đề này, lưu ý rằng mục cuối cùng được cắt cũng là ScrollBar tắt màn hình:

enter image description here

bố trí của tôi là khá chuẩn:

<?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="@color/background"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?android:attr/actionBarSize" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:background="@color/orange" 
      app:layout_scrollFlags="scroll|enterAlways"/> 

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


    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipeToRefresh" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <ExpandableListView 
      android:id="@+id/listView" 
      android:groupIndicator="@android:color/transparent" 
      android:layout_width="match_parent" 
      android:dividerHeight="0px" 
      android:layout_height="match_parent"/> 
    </android.support.v4.widget.SwipeRefreshLayout> 

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

Hãy nhìn vào câu trả lời của tôi lúc cho tôi biết nếu nó làm việc – waleedsarwar86

Trả lời

8

CoordinatorLayout chỉ làm việc với RecyclerView hoặc NestedScrollView.Try Gói ExapandableListView của bạn bên trong NestedScrollView hoặc sử dụng mã bên dưới để làm cho NestedScrollingEnable cho ExpandableListView.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    expandablelistView.setNestedScrollingEnabled(true); 
}else { 
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mSwipeLayout.getLayoutParams(); 
    params.bottomMargin = heightOfAppBarCompat; 
    mSwipeLayout.setLayoutParams(params); 
} 

Sửa Bạn có thể làm cho công việc di chuyển như mong đợi trước 21 với tuyên bố khác.

+0

Bạn nên nói tốt hơn "RecyclerView -OR- NestedScrollView "... –

+1

@MartinPfeffer Cảm ơn bạn đã chỉnh sửa – waleedsarwar86

+0

Yup, thiết lập cuộn lồng nhau được bật trên bản ExpandableListView sửa nó. Tôi đã thêm vào một hack để trả lời của bạn cho các thiết bị trước v21, hy vọng bạn không nhớ. – Graeme

0

Tôi sẽ viết nó làm nhận xét, nhưng về mặt khả năng đọc, tôi sẽ xóa thông tin này dưới dạng câu trả lời. Nếu nó không hoạt động, hãy cho tôi biết và tôi sẽ xóa nó ... Tôi đoán bạn nên cho Thanh công cụ biết cách tương tác. Trong ứng dụng của tôi thanh công cụ trông như thế này:

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

xin lưu ý các "ứng dụng: layout_collapseMode"

0
private int mPreviousVisibleItem; 


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     expListView.setNestedScrollingEnabled(true); 
    } else { 
     expListView.setOnScrollListener(new AbsListView.OnScrollListener() { 

      @Override 
      public void onScrollStateChanged(AbsListView view, int scrollState) { 
      } 

      @Override 
      public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 
       if (firstVisibleItem > mPreviousVisibleItem) { 
        appBarLayout.setExpanded(false, true); 
       } else if (firstVisibleItem < mPreviousVisibleItem) { 
        appBarLayout.setExpanded(true, true); 
       } 
       mPreviousVisibleItem = firstVisibleItem; 
      } 
     }); 
    } 
Các vấn đề liên quan