Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: roatating images in a loop
    primarykey
    data
    text
    <p>I am trying with no success to modify the code example from:</p> <p><a href="http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html" rel="nofollow">http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html</a></p> <p>so it will rotate the images in a loop, when clicking on the image once. (second click should pause).</p> <p>I tried using Handler and threading but cannot update the view since only the main thread can update UI.</p> <p>Exception I get from the code below:</p> <p>android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.</p> <p>[in 'image1.startAnimation(rotation);' ('applyRotation(0, 90);' from the main thread)]</p> <pre><code>package com.example.flip3d; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.AccelerateInterpolator; import android.widget.ImageView; public class Flip3d extends Activity { private ImageView image1; private ImageView image2; private boolean isFirstImage = true; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image1 = (ImageView) findViewById(R.id.image01); image2 = (ImageView) findViewById(R.id.image02); image2.setVisibility(View.GONE); image1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (isFirstImage) { applyRotation(0, 90); isFirstImage = !isFirstImage; } else { applyRotation(0, -90); isFirstImage = !isFirstImage; } } }); } private void applyRotation(float start, float end) { // Find the center of image final float centerX = image1.getWidth() / 2.0f; final float centerY = image1.getHeight() / 2.0f; // Create a new 3D rotation with the supplied parameter // The animation listener is used to trigger the next animation final Flip3dAnimation rotation = new Flip3dAnimation(start, end, centerX, centerY); rotation.setDuration(500); rotation.setFillAfter(true); rotation.setInterpolator(new AccelerateInterpolator()); rotation.setAnimationListener(new DisplayNextView(isFirstImage, image1, image2)); if (isFirstImage) { image1.startAnimation(rotation); } else { image2.startAnimation(rotation); } } } </code></pre> <p>How can I manage to update the UI and control the rotation within onClick listener?</p> <p>Thank you,</p> <p>Oakist</p>
    singulars
    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