2016-02-19 59 views
0

當用戶位於佈局頂部並向下滾動時,我想關閉對話框。這是到目前爲止我的代碼:當用戶位於頂部並向下滾動時關閉對話框

XML:

<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:id="@+id/coordinatorLayout" 
    android:layout_height="match_parent" 
    android:background="@color/White"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/White"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

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

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="0.99" 
        android:gravity="center" 
        android:text="@string/hello" 
        android:textColor="?attr/colorPrimary" 
        android:textSize="25sp" 
        app:layout_collapseMode="pin" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_gravity="bottom" 
        android:layout_weight="0.01" 
        android:background="?attr/colorPrimary" 
        app:layout_collapseMode="pin" /> 
      </LinearLayout> 

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

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

    <ListView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/listViewDialog" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/White" 
     android:divider="@null" 
     android:nestedScrollingEnabled="true" 
     android:padding="16dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

我試圖像許多事情上滾動監聽器列表視圖,但這個檢測,只有當用戶滾動到項目0。但我想關閉該對話框當用戶處於完整佈局的頂部時,因爲列表視圖上方有文本視圖。

+0

起初我建議你使用RecyclerView y並且請顯示更多的代碼。 –

+0

你想看什麼代碼? – blueman3399

+0

您試圖隱藏對話框的實現。 –

回答

0

您可以使用帶有LayoutManager而不是ListView的RecyclerView。該LayoutManager具有一個名爲findFirstCompletelyVisibleItemPosition()的功能。這會返回RecyclerView中第一個完全可見的項目。所以這將返回0,如果它在列表的頂部。在你的ScrolListener中加入這個,你就是這樣設置:)

相關問題