无法在SlidingUpPanelLayout Xamarin Android中使用ScrollView布局

Lon*_*Dao 6 c# android xamarin.android android-scrollview xamarin

我在我的代码中使用了这个库.基本上我在SlidingUp面板布局上有一个ScrollView.代码如下:

<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>
Run Code Online (Sandbox Code Playgroud)

我想要实现的是,如果展开SlidingUpPanelLayout,用户应该能够滚动ScrollView.如果ScrollView滚动到顶部(用户在手机上向下滚动)并且用户继续向下滚动,则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;
        };
Run Code Online (Sandbox Code Playgroud)

基本上我将SlidingEnable设置为true/false以更改滚动事件侦听器.

但是,ScrollView存在问题.它仅在ScrollView向上滚动然后向下滚动时触发.

无论如何,我认为我的方法不是一个好方法.有什么建议吗?此外,当我查看Android原生的AndroidSlidingUpPanel库时,似乎它已经支持SlidingUpPanelLayout中的ScrollView已开箱即用.不确定我是否正确.

我也不确定是否与SlidingUp面板的NestedScrollingEnabled = true有任何关系,但我在Stackoverflow上看到了很少的建议.

干杯,

San*_*ker -1

尝试使用nestedScrollview而不是scrollview

NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.scrollView);
scrollView.setFillViewport (true);
Run Code Online (Sandbox Code Playgroud)