【发布时间】:2017-09-24 13:58:32
【问题描述】:
我在我的代码中使用了这个库。基本上我在 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>
我想要实现的是,如果 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;
};
基本上我将 SlidingEnable 设置为 true/false 以更改滚动事件侦听器。
但是,ScrollView 有问题。仅在 ScrollView 向上滚动再向下滚动时触发。
无论如何,我认为我的方法不是一个好方法。有什么建议吗?此外,当我查看 Android 本机上的 AndroidSlidingUpPanel 库时,它似乎已经支持在 SlidingUpPanelLayout 内开箱即用的 ScrollView。不知道我说的对不对。
我也不确定是否与 SlidingUp 面板的 NestedScrollingEnabled = true 有任何关系,但我在 Stackoverflow 上看到的建议很少。
干杯,
【问题讨论】:
标签: c# android xamarin xamarin.android android-scrollview