Micro-trust Friends circle above the picture cover, QQ space to say that the above picture cover has a pull rebound effect, these are used to achieve the scroll bar. Pull down and bounce back to the original position when it's loosened. You can see the background picture when you drop. So here is a brief introduction to the implementation of this effect.
1. Effect drawing
This phone shows a limited resolution, very old mobile phone debugging.
2, with rebound effect Bouncescrollview
Package com.org.scroll;
Import Android.content.Context;
Import Android.graphics.Rect;
Import Android.util.AttributeSet;
Import android.view.MotionEvent;
Import Android.view.View;
Import android.view.animation.TranslateAnimation;
Import Android.widget.ScrollView; /** * ScrollView rebound effect of the implementation of * * public class Bouncescrollview extends ScrollView {Private View inner;//child view PR
ivate float y;//Click on the y-coordinate//rectangle (This is just a form, just to determine whether the animation is needed.)
Private Rect normal = new Rect (); Private Boolean iscount = false;//whether to start computing the public Bouncescrollview (context context, AttributeSet Attrs) {super (C
Ontext, Attrs); /*** * Work is done based on the XML build view. The function is called at the end of the build view, after all child views have been added.
Even if the subclass overrides the Onfinishinflate * method, the method of the parent class should be called so that the method can be executed.
* * @Override protected void onfinishinflate () {if (Getchildcount () > 0) {inner = getchildat (0); }/*** * Listener Touch/@Override public boolean ontouchevent (motionevent ev) {if inner!= n Ull) {commontouchevent (EV);
return super.ontouchevent (EV); /*** * Touch Event * * @param EV/public void commontouchevent (motionevent ev) {int action = EV
. Getaction ();
Switch (action) {case MotionEvent.ACTION_DOWN:break;
Case MOTIONEVENT.ACTION_UP://Fingers loose.
if (Isneedanimation ()) {animation ();
Iscount = false;
} break; /*** * Excludes the first move calculation because it is not possible to get the y-coordinate in motionevent.action_down for the first time, * because this is the Myscrollview touch event passed to ListView's child item above. So start with the second calculation. * However, we also have to initialize, that is, the first time we move the sliding distance to 0.
After the record is accurate, the normal execution.
* * Case MotionEvent.ACTION_MOVE:final float prey = y;//y-coordinate when pressed Nowy = Ev.gety ()/Time Y coordinate
int deltay = (int) (prey-nowy)//sliding distance if (!iscount) {deltay = 0;//here is 0.
} y = nowy; When scrolling to the top or bottom will not scroll again, then move the layout if (Isneedmove ()) {//Initialize the header rectangle if (normal.isempty()) {///save normal layout position Normal.set (Inner.getleft (), Inner.gettop (), Inner.getright (), Inne
R.getbottom ()); }//LOG.E ("JJ", "Rectangle:" + inner.getleft () + "," + inner.gettop ()//+ "," + inner.getright () + "," + Inne
R.getbottom ()); Mobile Layout Inner.layout (Inner.getleft (), Inner.gettop ()-DELTAY/2, Inner.getright (), Inner.getbottom
()-DELTAY/2);
} Iscount = true;
Break
Default:break; }/*** * Back-shrink animation/public void animation () {//Open mobile animation translateanimation ta = new Translatea
Nimation (0, 0, inner.gettop (), normal.top);
Ta.setduration (200);
Inner.startanimation (TA);
Set back to normal layout position inner.layout (Normal.left, Normal.top, Normal.right, Normal.bottom);
LOG.E ("JJ", "return:" + Normal.left + "," + Normal.top + "," + normal.right//+ "," + Normal.bottom);
Normal.setempty (); }//Whether you need to openStart Painting public boolean isneedanimation () {return!normal.isempty ();
/*** * need to move layout inner.getmeasuredheight (): Gets the total height of the control * * getheight (): Gets the height of the screen * * @return
*/Public Boolean isneedmove () {int offset = inner.getmeasuredheight ()-getheight ();
int scrolly = getscrolly ();
LOG.E ("JJ", "scrolly=" + scrolly);
0 is the top, the back one is the bottom if (scrolly = 0 | | scrolly = offset) {return true;
return false; }
}
3, Mainactivity
Package com.org.activity;
Import Android.os.Bundle;
Import android.app.Activity;
Import Android.view.Menu;
Import Android.view.Window;
public class Mainactivity extends activity {
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Requestwindowfeature (window.feature_no_title);
Setcontentview (R.layout.activity_main);
}
@Override Public
Boolean oncreateoptionsmenu (Menu menu) {
//inflate the menu; This adds items to the action Bar If it is present.
Getmenuinflater (). Inflate (R.menu.activity_main, menu);
return true;
}
This does not do anything, mainly look at the layout, as well as the Bouncescrollview class.
4, Activity_main layout
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http:// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:orien"
tation= "vertical" > <include layout= "@layout/common_title_bg"/> <com.org.scroll.bouncescrollview Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:background= "@drawable/covers ATION_BG "android:focusable=" true "android:focusableintouchmode=" true "> <linearlayout Andro Id:layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" an droid:paddingtop= "10.0dip" > <relativelayout android:id= "@+id/accountsetting" Android:lay Out_width= "Fill_parent" android:layout_height= "63.0dip" android:background= "#80ffffff" Android: Focusable= "true" > <framelayoUT android:id= "@+id/framelayout1" android:layout_width= "54.0dip" android:layout_height= "5 4.0dip "android:layout_centervertical=" true "android:layout_marginleft=" 10.0dip > & Lt;imageview android:id= "@+id/face" android:layout_width= "50.0dip" Android:layout_h
eight= "50.0dip" android:layout_gravity= "center" android:contentdescription= "@null" android:src= "@drawable/h0"/> <imageview android:id= "@+id/statusicon" Android : layout_width= "18.0dip" android:layout_height= "18.0dip" android:layout_gravity= "Bottom|right|cen
ter "android:contentdescription=" @null "/> </FrameLayout> <imageview Android:id= "@+id/imageview1" android:layout_width= "wrap_content" android:layout_height= "Wrap_cont" Ent "Android:Layout_alignparentright= "true" android:layout_centervertical= "true" android:layout_marginright= "10.0 Dip "android:contentdescription=" @null "android:duplicateparentstate=" true "/> <tex Tview android:id= "@+id/status" android:layout_width= "Wrap_content" android:layout_height=
"Wrap_content" android:layout_alignbottom= "@+id/nick" android:layout_marginright= "10.0dip" android:layout_toleftof= "@id/imageview1" android:duplicateparentstate= "true" android:text= "online"/&G
T <textview android:id= "@+id/nick" android:layout_width= "Wrap_content" android:layout_he
ight= "Wrap_content" android:layout_centervertical= "true" android:layout_marginleft= "10.0dip" android:layout_marginright= "69.0dip" android:layout_torightof= "@id/framelayout1" Android:duplica TeparentstAte= "true" android:ellipsize= "End" android:singleline= "true"/> </RelativeLayout> <linearlayout android:layout_width= "match_parent" android:layout_height= "600DP" Andro id:layout_margintop= "16.0dip" android:layout_weight= "2.13" android:background= "#ffffffff" Andro id:orientation= "vertical" > <textview android:id= "@+id/my_profile" Android:layout_w Idth= "Fill_parent" android:layout_height= "44.0dip" android:background= "#800000ff" Android : Clickable= "true" android:gravity= "center_vertical" android:paddingleft= "10.0dip" Android :p addingright= "10.0dip" android:text= "title One"/> <linearlayout android:layout_width= "f Ill_parent "android:layout_height=" wrap_content "android:layout_margintop=" 16.0dip "Andro id:orientation= "Vertical"> <relativelayout android:id=" @+id/set_feedback "android:layout_width=" fill _parent "android:layout_height=" 44.0dip "android:background=" #8000ffff "android:cli Ckable= "true" android:focusable= "true" > <textview android:layout_width= "
Wrap_content "android:layout_height=" Wrap_content "android:layout_centervertical=" true " android:layout_marginleft= "12.0dip" android:duplicateparentstate= "true" android:g Ravity= "center_vertical" android:text= "Feedback"/> </RelativeLayout> </linearlay out> </LinearLayout> </LinearLayout> </com.org.scroll.BounceScrollView> </linear Layout>
Hopefully this article will help you learn about Android software programming.