Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code> public class AnimationActivity extends Activity { private boolean isUp; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ((Button) findViewById(R.id.button1)) .setOnClickListener(new OnClickListener() { public void onClick(final View v) { final float direction = (isUp) ? -1 : 1; final float yDelta = getScreenHeight() - (2 * v.getHeight()); final int layoutTopOrBottomRule = (isUp) ? RelativeLayout.ALIGN_PARENT_TOP : RelativeLayout.ALIGN_PARENT_BOTTOM; final Animation animation = new TranslateAnimation(0,0,0, yDelta * direction); animation.setDuration(500); animation.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) { } public void onAnimationRepeat(Animation animation) { } public void onAnimationEnd(Animation animation) { // fix flicking // Source : http://stackoverflow.com/questions/9387711/android-animation-flicker TranslateAnimation anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f); anim.setDuration(1); v.startAnimation(anim); //set new params LayoutParams params = new LayoutParams(v.getLayoutParams()); params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(layoutTopOrBottomRule); v.setLayoutParams(params); } }); v.startAnimation(animation); //reverse direction isUp = !isUp; } }); } private float getScreenHeight() { DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); return (float) displaymetrics.heightPixels; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload