我正在使用C#和Xamarin创建一个Android应用程序。我已经扩展了ScrollView。以下是我的代码:
如果有人能帮我并让我知道我做错了什么,那将是一大帮助。看起来我做的一切都是对的,但可能有些遗漏。
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");
}
}
如果有人能帮我并让我知道我做错了什么,那将是一大帮助。看起来我做的一切都是对的,但可能有些遗漏。