Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: How to animate between activities?
    primarykey
    data
    text
    <p>I have a question about animations in Android. I've made an app which has a lot of products in it, you can switch products now by swiping the screen left to right (go to the next product in the list) However it just loads like any other activity now.</p> <p>What I want is what a lot of other apps have as well, the swiping needs to make the old activity go left and out of the screen, while the new one comes in right at the same time.</p> <p>I've searched and read a lot but I really don't know where to even begin.</p> <p>My Products are activities, and this is the way they are switched now:</p> <pre><code>@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH) return false; // left to right swipe if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { for(HashMap h: products) { if (h.get("id").toString().equals(id)) { int index = products.indexOf(h)-1; if (index != -1) { HashMap product = products.get(index); dialog = ProgressDialog.show(ProductActivity.this, "", "Laden...", true); Intent i = new Intent(ProductActivity.this, ProductActivity.class); i.putExtra("id", product.get("id").toString()); i.putExtra("profileId", profileId); i.putExtra("score", product.get("score").toString()); i.putExtra("products", products); startActivity(i); } else { Toast.makeText(ProductActivity.this, "Dit is het eerste product in de lijst.", Toast.LENGTH_LONG).show(); } } } } //right to left swipe else if(e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { for(HashMap h: products) { if (h.get("id").toString().equals(id)) { int index = products.indexOf(h)+1; if (index != products.size()) { HashMap product = products.get(index); dialog = ProgressDialog.show(ProductActivity.this, "", "Laden...", true); Intent i = new Intent(ProductActivity.this, ProductActivity.class); i.putExtra("id", product.get("id").toString()); i.putExtra("profileId", profileId); i.putExtra("score", product.get("score").toString()); i.putExtra("products", products); startActivity(i); } else { Toast.makeText(ProductActivity.this, "Dit is het laatste product in de lijst.", Toast.LENGTH_LONG).show(); } } } } } catch (Exception e) { // nothing } return false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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