Step 1: write several global variables to record:
/**
* Record if the sliding page is the last page
*/
private boolean isHomeLastPage = false;
private boolean isHomeDragPage = false;
The second step is to get the last element by implementing the listening onpageselected() in VP
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
Log.e("videoPositionposition", position + "");
//get the last page/position equals the last element
isHomeLastPage = position == datas.size() - 1;
}
The third step is to implement the listening onpagescrollstatechanged() in VP to determine whether the current sliding state is in,
@Override
public void onPageScrollStateChanged(int state) {
// 0: do nothing 1: start sliding 2: end sliding Scrolling listener
isHomeDragPage = state == ViewPager2.SCROLL_STATE_DRAGGING;
//judge that the last one will not be loaded
}
The fourth step is to implement onpagescrolled() 1.
1. Judge whether it is the last element
2. Whether it is in sliding state,
3. The offset of posionoffsetpixels is 0.
the work is done, and the judgment of VP sliding to the last page has been done
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//Determine the last element and slide state, and the offset is 0
Log.e("vp2CCC", "vp2CCC" + isHomeLastPage + " " + isHomeDragPage + " " + positionOffsetPixels);
if (isHomeLastPage && isHomeDragPage && positionOffsetPixels == 0) { //the current page is the last page and is dragging and the pixel offset is 0
Toast.makeText(getActivity(), "The current page is the last page", Toast.LENGTH_SHORT).show();
} else {
}
}
Read More:
- JS Mobile Page to determine whether it is iPhone X, and then set the corresponding height of the element?
- The requested page cannot be accessed because the related configuration data for the page is invalid
- Latex sets page margin, page size, page margin and geometry macro package
- Vs error: there is an error in the script of the current page
- Activity of Android studio_ main.xml Unable to preview (gray page)
- How to Fix “the data of store is lost after Vue refreshes the page”
- The icon on the layui page is not displayed, and an error message is reported: Failed to decode downloaded font …..
- Pychar oserror: [winerror 1455] the page file is too small to complete the operation.
- [math processing error] problem solving (the difference between F5 refresh page and Ctrl / shift + F5 refresh page)
- When using CSS to write the registration page, we found that the editing effect is not effective
- The pychar / pytorch page file is too small to complete the operation
- Error: importerror: DLL load failed: the page file is too small to complete the operation.
- After Vue is packaged, a blank page appears, an error is reported in the resource request, and there is no error handling scheme
- In Struts2, the value read from the foreground JSP page is null
- Error 10002 – Security header is not valid appears on the Django Oscar page
- The total row of the Element table entry page is not displayed
- Transfer: completely solve the problem that the browser home page is tampered by deleting the script file
- Abnormal display of page object moved to here
- Three methods of JavaScript jump to new page
- Using nginx page to report an error occurred