Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally sorted it... it's very long winded as I couldn't get to grips with the animation end event because of the multiple animations.. so probably not the best way but it works and I'm happy!</p> <p>For anyone who wants to know how.. or wants to adapt it to make it better here it is:</p> <p><strong>Main Activity (MyTransition.java):</strong></p> <pre><code>import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.LinearLayout; import java.util.Vector; public class MyTransition extends AppCompatActivity { ImageView slide_0; ImageView slide_1; ImageView lastSlide; Vector&lt;Integer&gt; imageIds; LinearLayout linLayout; int count = 0; private Handler transparencyHandler = new Handler(); private Handler timerHandler = new Handler(); private Runnable transparencyTimer = new Runnable() { public void run() { if (lastSlide == slide_0) { slide_1.setBackgroundColor(getResources().getColor(android.R.color.transparent)); slide_1.setImageResource(0); } else { slide_0.setBackgroundColor(getResources().getColor(android.R.color.transparent)); slide_0.setImageResource(0); } } }; private Runnable timer = new Runnable() { public void run() { if (lastSlide == slide_0) { slide_1.setImageResource(0); slide_1.setImageResource(imageIds.get((count + 1) % (imageIds.size()))); slide_1.startAnimation(AnimationUtils .loadAnimation(MyTransition.this, R.anim.transition_down)); lastSlide = slide_1; } else { slide_0.setImageResource(0); slide_0.setImageResource(imageIds.get((count + 1) % (imageIds.size()))); slide_0.startAnimation(AnimationUtils .loadAnimation(MyTransition.this, R.anim.transition_up)); lastSlide = slide_0; } count++; transparencyHandler.postDelayed(transparencyTimer, 1000); timerHandler.postDelayed(timer, 8000); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test2); slide_0 = (ImageView) findViewById(R.id.slide_1); slide_1 = (ImageView) findViewById(R.id.slide_2); imageIds = new Vector&lt;Integer&gt;(); imageIds.add(R.drawable.first_image); imageIds.add(R.drawable.second_image); // Load Image 1 slide_0.setImageResource(imageIds.get(0)); slide_0.startAnimation(AnimationUtils.loadAnimation(this, R.anim.transition_down)); lastSlide = slide_0; timerHandler.postDelayed(timer, 8000); } } </code></pre> <p><strong>Layout (test2.xml):</strong></p> <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/frame" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;ImageView android:id="@+id/slide_1" android:layout_gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerCrop" /&gt; &lt;ImageView android:id="@+id/slide_2" android:layout_gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerCrop" /&gt; &lt;/FrameLayout&gt; </code></pre> <p><strong>Animation (transition_down.xml):</strong></p> <pre><code>&lt;set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"&gt; &lt;alpha android:fromAlpha="0.0" android:toAlpha="2.0" android:duration="2000" android:repeatCount="0" android:fillAfter="true" /&gt; &lt;scale android:fromXScale="1" android:toXScale="1.2" android:fromYScale="1" android:toYScale="1.2" android:duration="10000" android:repeatCount="0" android:fillAfter="true" /&gt; &lt;alpha android:fromAlpha="2.0" android:toAlpha="0.0" android:duration="2000" android:repeatCount="0" android:startOffset="8000" android:fillAfter="true" /&gt; &lt;/set&gt; </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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