How to judge the ScrollView of Android sliding to the bottom?

Source: Internet
Author: User

Scroll to the top of the judging:

getscrolly () = = 0

Scroll to the bottom to judge:

View Childview = getchildat (0);

Childview.getmeasuredheight () <= getscrolly () + getheight ();

Where Getchildat said to get ScrollView's child View

Childview.getmeasuredheight () indicates the height of the child view,

Getscrolly () means that the scroll distance of the y-axis is obtained,

GetHeight () is the height of the ScrollView

Getscrolly () When the maximum is reached, the height of the scrollview is equal to the height of its content.

There are two ways to determine where to slide:

1, implement Ontouchlistener to monitor whether to slide to the bottom

Ontouchlistener ontouchlistener=new Ontouchlistener () {

@Override

public boolean OnTouch (View V, motionevent event) {

Switch (event.getaction ()) {

Case MOTIONEVENT.ACTION_UP:

if (childview ! = null && childview . Getmeasuredheight () <= getscrolly () + getheight ()) {

} else if (getscrolly () = = 0) {

}

Break

}

return false;

}

}

2, rewrite the method of ScrollView onscrollchanged, in the onscrollchanged function to judge

public class Myscrollview extends ScrollView

{

Public Myscrollview (Context context)

{

Super (context);

}

Public Myscrollview (context context, AttributeSet AttributeSet)

{

Super (Context,attributeset);

}

@Override

protected void onscrollchanged (int l, int t, int oldl, int Oldt)

{

View view = (view) Getchildat (Getchildcount ()-1);

int d = View.getbottom ();

D-= (GetHeight () +getscrolly ());

if (d==0)

{

You is at the end of the list in ScrollView

Do-what-wanna do here

}

Else

Super.onscrollchanged (L,t,oldl,oldt);

}

}

This article welcome reprint, Reprint please indicate the source and the author

Source: Http://blog.sina.com.cn/staratsky

Meteor

Android Development Group, share the solutions and experience of problems in development, welcome everyone to join, group number: 293872059


How to judge the ScrollView of Android sliding to the bottom?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.