In many news projects , Let's slide down the list to see the news , Generally, drop-down refresh will be implemented , Pull up to load more functions , Sometimes we slide to the bottom , At this point, it is very troublesome to refresh or pull up to the top , So you need to click the top , Many projects have this design , So how to achieve it ?

The following provides an implementation idea , It's not too much trouble , Direct code :
public class GoTopScrollView extends ScrollView implements
View.OnClickListener { // Top button private ImageView goTopBtn; public
GoTopScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); } public void setScrollListener(ImageView
goTopBtn) { this.goTopBtn = goTopBtn; this.goTopBtn.setOnClickListener(this); }
@Override protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt); // Sliding distance exceeds 200px, The up button appears if(t > 200) {
goTopBtn.setVisibility(View.VISIBLE); } else {
goTopBtn.setVisibility(View.GONE); } } @Override public void onClick(View v) {
if(v.getId() == R.id.imageView) { this.smoothScrollTo(0, 0); } } }

After that, the user-defined ScrollView Embedded in ListView Outside , The method of use is as follows : stay ScrollView Add a ImageView,ScrollView It's essentially a FrameLayout,setCrollListener(imageView) that will do

Technology