Activity_main.xml
<RelativeLayout 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"
>
<Button
android:id="@+id/clickMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Click me!" />
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/clickMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Click me!" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity { DecelerateInterpolator sDecelerator = new DecelerateInterpolator(); OvershootInterpolator sOvershooter = new OvershootInterpolator(10f); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button clickMeButton = (Button) findViewById(R.id.clickMe); clickMeButton.animate().setDuration(200); clickMeButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { if (arg1.getAction() == MotionEvent.ACTION_DOWN) { clickMeButton.animate().setInterpolator(sDecelerator). scaleX(.7f).scaleY(.7f); } else if (arg1.getAction() == MotionEvent.ACTION_UP) { clickMeButton.animate().setInterpolator(sOvershooter). scaleX(1f).scaleY(1f); } return false; } }); } }
DecelerateInterpolator - An interpolator where the rate of change starts out quickly
and and then decelerates.
OvershootInterpolator
- An interpolator where the change flings forward and
overshoots the last value then comes back.
22
No comments:
Post a Comment