An example of how to implement the elastic sliding of a View.
Elastic sliding Principle
A large slide is not a few small slides and completed within a period of time. Better User Experience
There are many implementation methods, including Scroller, animation, and latency policies.
Use Handler for Elastic sliding
You can see that the Button slides toward. Note that the View content is changed here.
You can try removing the RelitiveLayout of the outer layer of the Button and placing the id under the Button. YesText slide of 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 FRAME_OUT = 30; private static final int DELAYED_TIME = 30; private RelativeLayout button; private int mcount; private Handler handler = new Handler(){ public void handleMessage(Message msg){ switch (msg.what) { case MESSAGE_SCROLL_TO: mcount++; if (mcount <= FRAME_OUT) { float fraction = mcount / (float)FRAME_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); }}
Reference: Android development art Exploration