The principle of elastic sliding
A large slide is not a number of minor slides and is completed within a time period. A better user experience
There are many ways to implement it, including using scroller, animation, and latency strategies.
Using handler to achieve elastic sliding
The effect can see the button buttons sliding. Note that this changes the contents of the view.
You can try to remove the outer relitivelayout of the button and place the ID under the button. Found the text slide of the button
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent "android:layout_height=" match_parent "> <relativelayout android:id=" @+id/button1 "android:layout_height=" Wrap_content "android:layout_width=" 300DP "android:layout_alignparentright=" true "android:layout_alignparenttop=" True "> <button android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android:layout_
Alignparentright= "true" android:layout_alignparenttop= "true" android:text= "button"/> </RelativeLayout>
</RelativeLayout> import Android.os.Bundle;
Import Android.os.Handler;
Import Android.os.Message;
Import Android.widget.RelativeLayout; public class Mainactivity extends activity {private static final int message_scroll_to = 1; private static final int FRAM
E_out = 30;
private static final int delayed_time = 30;
Private Relativelayout button;
private int mcount; Private Handler Handler = new Handler () {public void Handlemessage(msg) {switch (msg.what) {case message_scroll_to:mcount++; if (mcount <= frame_out) {Float fraction = mcount/(float) FRA
Me_out;
int scrollx = (int) (fraction * 100);
Button.scrollto (SCROLLX, 0);
Handler.sendemptymessagedelayed (message_scroll_to, delayed_time);
} break;
Default:break;
}
}
}; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.activity_main);
button = (relativelayout) Findviewbyid (R.id.button1);
Handler.sendemptymessagedelayed (message_scroll_to, delayed_time); }
}
The above is a small set to introduce the Android use handler to achieve view elastic sliding, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!