Android imitation IOS rebound effect ScrollView rebound summary, androidscrollview

Source: Internet
Author: User

Android imitation IOS rebound effect ScrollView rebound summary, androidscrollview

Summary

The pull-back Effect of IOS should be similar to the requirements in the project. Most of the items I searched online are scrollview.

I tried and found some problems.

The following code is a small modification I made to everyone. I don't think it is too much a problem.


Package com. example. myscrollview; 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;/*** Bolg: http://blog.csdn.net/aaawqqq? Viewmode = contents ** @ author baozi **/public class MyScrollView extends ScrollView {// The distance from the drag size = 4 means that only 1/4 private static final int size of the screen can be dragged = 4; private View inner; private float y; private Rect normal = new Rect (); public MyScrollView (Context context) {super (context);} public MyScrollView (Context context, AttributeSet attrs) {super (context, attrs) ;}@ Overrideprotected void onFinishInflate () {I F (getChildCount ()> 0) {inner = getChildAt (0) ;}@overridepublic boolean onTouchEvent (MotionEvent ev) {if (inner = null) {return super. onTouchEvent (ev);} else {commOnTouchEvent (ev);} return super. onTouchEvent (ev);} public void commOnTouchEvent (MotionEvent ev) {int action = ev. getAction (); switch (action) {case MotionEvent. ACTION_DOWN: y = ev. getY (); break; case MotionEvent. ACTION_UP: if (isNeedAnimation () {// Log. v ("mlguitar", "will up and animation"); animation ();} break; case MotionEvent. ACTION_MOVE: final float preY = y; float nowY = ev. getY ();/*** size = 4 indicates that the drag distance is 1/4 */int deltaY = (int) (preY-nowY)/size of the screen height; // scroll // scrollBy (0, deltaY); y = nowY; // when it is scrolled to the top or bottom, it will not be scrolled. Then, move the layout if (isNeedMove ()) {if (normal. isEmpty () {// Save the normal layout position normal. set (inner. getLeft (), inner. getTop (), inner. getRight (), inne R. getBottom (); return;} int yy = inner. getTop ()-deltaY; // move the layout inner. layout (inner. getLeft (), yy, inner. getRight (), inner. getBottom ()-deltaY);} break; default: break;} // enable animation mobile public void animation () {// enable mobile animation TranslateAnimation ta = new TranslateAnimation (0, 0, inner. getTop (), normal. top); ta. setDuration (1, 200); inner. startAnimation (ta); // set to return to the normal layout position inner. layout (normal. left, normal. top, normal. right, n Ormal. bottom); normal. setEmpty () ;}// whether to enable the animation public boolean isNeedAnimation () {return! Normal. isEmpty ();} // whether to move the layout public boolean isNeedMove () {int offset = inner. getMeasuredHeight ()-getHeight (); int scrollY = getScrollY (); if (scrollY = 0 | scrollY = offset) {return true;} return false ;}} // please wait until then // zookeeper // zookeeper without any bugs! // Zookeeper has been completed before // zookeeper has been executed before being executed ┛ ┗ ┻ ┛

The size parameter in the code is used to set the drag distance.

Size = 4 indicates that the view only slides 1/4 away from its fingers.

Size = 3 represents the 1/3 distance between the sliding fingers

Similarly

Demo: http://download.csdn.net/detail/aaawqqq/7629533


For better results, please contact me. Thank you.

I wish you all good code every day...



In android, how does one pull the listview out of the range and then has a rebound effect?

Open-source controls available on the Internet: PullToRefreshListView, a pull-down refresh control. Baidu will find it and use it online.
 
Scrollview problems during iOS development

Simply put, add all your buttons not to self. view, but to UIScrollview, but calculate the contentSize of UIScrollview. Only in this way can scrollview scrolling be implemented.
 

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.