Sina refresh
This pull-down refresh method is relatively simple. Previous figure:
The refresh method is like this:
First, a headerview is required, that is, the data displayed in the header during refresh. The layout of this view is determined by yourself.
Others are not particularly important. What is important is the capture of user touch events. Some methods on GitHub are more formal. I will try it myself, it mainly captures user click events to calculate the locations touched by the user, and then updates the position of the head layout.
Post this important code:
case MotionEvent.ACTION_MOVE:currentY = (int) ev.getY();if (!ISREFRESH) {if (currentY > getHeight()/10) {progressBar.setVisibility(0);tipsTextview.setVisibility(0);lastUpdatedTextView.setVisibility(0);tempY=tempY+5;headView.setPadding(0, -1 * headContentHeight + tempY, 0, 0);headView.invalidate();if (tempY >= headContentHeight) {tempY = 0;add.GetNewTExt("new text");ISREFRESH = true;}}}break;case MotionEvent.ACTION_UP:progressBar.setVisibility(8);tipsTextview.setVisibility(8);lastUpdatedTextView.setVisibility(8);ISREFRESH = false;break;}
Isrefresh determines whether to refresh. If the refresh is finished, it does not need to be loaded. Then, it needs to hide the head layout and use headview. the setpadding method is used to control the distance between the head layout and the top position in real time to achieve a slow display. As for some other effects, such as slowly hiding when pulling up, the effects are the same.
--------------------------------------------------------------------------------
Gmail refresh
The pull-down refresh effects of Gmail (like) after 4.0 are cool,
This pull-down refresh effect becomes a line.
There are two implementation methods for this effect, so I will not post the code, which is relatively simple.
1. Implementation through drawing
Set a header layout with a size smaller than 5 or a ratio. This layout is just a layout with nothing in it. Then, when the above-mentioned user operations are performed, the head layout begins to draw, and draw from the center to both sides. In fact, it is to draw rect, and control the painting speed and the position touched by the user, you can update the drawing dynamically through the interface you have defined, but I personally feel that this method is not very good.
2. Use progress to display
This is simple, that is, adding two SS in the header layout. You don't need to talk about the progress bar implementation of progress. You can judge the update speed of the progress bar by using the user's position, what's more, the progress bar needs to go back when the user slides up. These are simple methods.
If there are any mistakes, correct them.