首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法在SlidingUpPanelLayout Xamarin安卓中使用ScrollView布局

无法在SlidingUpPanelLayout Xamarin安卓中使用ScrollView布局
EN

Stack Overflow用户
提问于 2017-04-27 08:03:41
回答 1查看 473关注 0票数 6

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

代码语言:javascript
运行
复制
<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是展开的,用户应该能够滚动的ScrollView。如果ScrollView滚动到顶部(用户在手机上向下滚动),并且用户不断向下滚动,则SlidingUpPanelLayout应该会折叠。

我实现了以下代码:

_slidingUpPanelLayout.NestedScrollingEnabled =真;

代码语言:javascript
运行
复制
        _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有一个问题。它只在ScrollView向上滚动然后向下滚动时触发。

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

我也不确定SlidingUp面板的NestedScrollingEnabled = true是否有什么关系,但我在Stackoverflow上看到的建议很少。

干杯,

EN

Stack Overflow用户

发布于 2017-05-05 15:21:49

尝试使用nestedScrollview而不是滚动视图

代码语言:javascript
运行
复制
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.scrollView);
scrollView.setFillViewport (true);
票数 -1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43646491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档