2017-04-27 33 views
6

裏面我在代碼中使用這個庫。基本上我在SlidingUp面板佈局上有一個ScrollView。代碼如下:不能使用滾動型佈局SlidingUpPanelLayout Xamarin的Android

<cheesebaron.slidinguppanel.SlidingUpPanelLayout 
       android:id="@+id/sliding_layout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="bottom"> 
       <android.support.v4.view.ViewPager 
        android:id="@+id/HomeFrameLayout" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 
       <ScrollView 
        android:id="@+id/slidingPanelScrollView" 
        android:layout_height="match_parent" 
        android:layout_width="match_parent" 
        android:background="@android:color/transparent" 
        android:clickable="true" 
        android:focusable="false"> 
        <RelativeLayout 
         android:layout_height="match_parent" 
         android:layout_width="match_parent"> 
         <RelativeLayout 
          android:id="@+id/cardHolderRelativeLayout" 
          android:layout_height="match_parent" 
          android:layout_width="380dp" 
          android:background="@android:color/transparent" 
          android:layout_centerHorizontal="true" 
          android:padding="10dp"> 
          <LinearLayout 
           android:id="@+id/linearLayout1" 
           android:layout_height="250dp" 
           android:layout_width="match_parent" 
           android:background="#FF0000" 
           android:layout_marginBottom="15dp" /> 
          <LinearLayout 
           android:id="@+id/linearLayout2" 
           android:layout_height="250dp" 
           android:layout_width="match_parent" 
           android:background="#00FF00" 
           android:layout_marginBottom="15dp" 
           android:layout_below="@id/linearLayout1" /> 
          <LinearLayout 
           android:id="@+id/linearLayout3" 
           android:layout_height="250dp" 
           android:layout_width="match_parent" 
           android:background="#0000FF" 
           android:layout_marginBottom="15dp" 
           android:layout_below="@id/linearLayout2" /> 
          <LinearLayout 
           android:id="@+id/linearLayout4" 
           android:layout_height="250dp" 
           android:layout_width="match_parent" 
           android:background="#0000FF" 
           android:layout_marginBottom="15dp" 
           android:layout_below="@id/linearLayout2" /> 
         </RelativeLayout> 
        </RelativeLayout> 
       </ScrollView> 
      </cheesebaron.slidinguppanel.SlidingUpPanelLayout> 

我想實現的是,如果SlidingUpPanelLayout擴展,用戶應該能夠滾動了滾動。如果滾動型滾動到其頂部(用戶在手機上向下滾動)和用戶一直滾動下去,SlidingUpPanelLayout應該崩潰了。

我執行以下代碼:

_slidingUpPanelLayout.NestedScrollingEnabled = TRUE;

 _scrollView.ViewTreeObserver.ScrollChanged += (sender, e) => 
     { 
      var y = _scrollView.ScrollY; 
      if (y < -20) 
      { 
       _slidingUpPanelLayout.SlidingEnabled = true; 
      } 

     }; 

     _slidingUpPanelLayout.PanelExpanded += (sender, args) => 
     { 
      RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.MatchParent); 
      _cardHolderRelativeLayout.LayoutParameters = layoutParams; 

      _slidingUpPanelLayout.SlidingEnabled = false; 
     }; 

基本上我將SlidingEnable設置爲true/false來更改滾動事件偵聽器。

然而,與滾動型的問題。它只在ScrollView向上滾動然後向下滾動時觸發。

無論如何,我不認爲我的做法是一個很好的辦法。任何建議?此外,當我看到在Android原生的AndroidSlidingUpPanel庫,好像它支持滾動型內SlidingUpPanelLayout外的箱子了。不知道我是否正確。

我也不能肯定是否有什麼關係NestedScrollingEnabled =真正的SlidingUp面板或沒有,但我看到#2相當一些建議。

乾杯,

回答

-1

嘗試使用,而不是滾動型

NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.scrollView); 
scrollView.setFillViewport (true); 
+0

它不工作nestedScrollview。我已經嘗試過了。請看看我的代碼,而不是像這樣提供隨機理論代碼。在詢問之前,我已經嘗試了幾種方法 –