【发布时间】:2014-12-19 18:45:41
【问题描述】:
我在 Xamarin 中使用 C# 创建一个 android 应用程序。我创建了滚动视图的扩展。这是我的代码
public class EndlessScroll : ScrollView
{
public EndlessScroll (Context context) : base (context)
{
}
public EndlessScroll(Context context, IAttributeSet attrs) : base(context, attrs)
{
}
public EndlessScroll(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
{
}
public interface OnScrollViewListener
{
void onScrollChanged(EndlessScroll v, int l, int t, int oldl, int oldt);
}
public OnScrollViewListener scrollViewListener;
public void setOnScrollViewListener(OnScrollViewListener scrollViewListener) {
this.scrollViewListener = scrollViewListener;
}
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
base.OnScrollChanged(l, t, oldl, oldt);
if (scrollViewListener != null) {
scrollViewListener.onScrollChanged(this, l, t, oldl, oldt);
}
}
}
}
我试图将它实现到另一个类中。我没有得到任何编译错误,但是当滚动视图到达底部时它不会注册。这是我在这里的代码。
public class getFromParse:Activity, EndlessScroll.OnScrollViewListener {
LinearLayout linear;
Button buttonSort;
Typeface font;
protected override void OnCreate (Bundle bundle)
{
Window.RequestFeature(WindowFeatures.NoTitle);
base.OnCreate (bundle);
SetContentView (Resource.Layout.debugLog);
EndlessScroll scroll = FindViewById <EndlessScroll> (Resource.Id.scrollView);
scroll.setOnScrollViewListener (this);
这里是滚动视图侦听器应该检测到它何时到达底部的位置。
public void onScrollChanged(EndlessScroll scrollView, int x, int y, int oldx, int oldy) {
// We take the last son in the scrollview
View view = (View) scrollView.GetChildAt(scrollView.ChildCount - 1);
int diff = (view.Bottom - (scrollView.Height + scrollView.ScrollY));
// if diff is zero, then the bottom has been reached
if (diff == 0) {
Console.WriteLine ("Scroll changed");
}
}
如果有人可以帮助我并让我知道我做错了什么,那将是一个很大的帮助。似乎我做的一切都是正确的,但我可能会遗漏一些东西。
【问题讨论】:
-
我知道你已经找到了解决办法,但是你试过这个控件吗? github.com/XLabs/Xamarin-Forms-Labs/wiki/CarouselView
标签: c# android xamarin xamarin.android scrollview