Note that there are some explanatory texts on larger screens.

plurals
  1. POview flipper is not flipping
    text
    copied!<p><strong>hi i have created a flip view in my activity I have 2 images that I need to get flipped ,but it is not flipping behalf I can just view my first image on the screen... I am giving my class file and xml below .. I need some solution</strong> </p> <pre><code> import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.widget.ViewFlipper; public class Viewflip extends Activity { private ViewFlipper viewFlipper; private float lastX; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery); viewFlipper = (ViewFlipper) findViewById(R.id.view_flipper); } // Method to handle touch event like left to right swap and right to left swap public boolean onTouchEvent(MotionEvent touchevent) { switch (touchevent.getAction()) { // when user first touches the screen to swap case MotionEvent.ACTION_DOWN: { lastX = touchevent.getX(); break; } case MotionEvent.ACTION_UP: { float currentX = touchevent.getX(); // if left to right swipe on screen if (lastX &lt; currentX) { // If no more View/Child to flip if (viewFlipper.getDisplayedChild() == 0) break; // set the required Animation type to ViewFlipper // The Next screen will come in form Left and current Screen will go OUT from Right viewFlipper.setInAnimation(this, R.anim.in_from_left); viewFlipper.setOutAnimation(this, R.anim.out_to_right); // Show the next Screen viewFlipper.showNext(); } // if right to left swipe on screen if (lastX &gt; currentX) { if (viewFlipper.getDisplayedChild() == 1) break; // set the required Animation type to ViewFlipper // The Next screen will come in form Right and current Screen will go OUT from Left viewFlipper.setInAnimation(this, R.anim.in_from_right); viewFlipper.setOutAnimation(this, R.anim.out_to_left); // Show The Previous Screen viewFlipper.showPrevious(); } break; } } return false; } } </code></pre> <p><strong>Xml file</strong></p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="vertical" &gt; &lt;ViewFlipper android:id="@+id/view_flipper" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="6dip" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="450dp" android:layout_height="450dp" android:layout_marginTop="15dp" android:src="@drawable/scene1" /&gt; &lt;/LinearLayout&gt; &lt;!-- Layout 2 for 2nd Screen --&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" &gt; &lt;ImageView android:id="@+id/imageView2" android:layout_width="450dp" android:layout_height="450dp" android:layout_marginTop="15dp" android:src="@drawable/scene2" /&gt; &lt;/LinearLayout&gt; &lt;/ViewFlipper&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>Giving my animation xml files below</strong></p> <pre><code> **in_from_left.xml** &lt;set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"&gt; &lt;translate android:fromXDelta="-100%" android:toXDelta="0%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="1400" /&gt; &lt;/set&gt; **in_from_right.xml** &lt;set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"&gt; &lt;translate android:fromXDelta="100%" android:toXDelta="0%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="1400" /&gt; &lt;/set&gt; **out_to_left.xml** &lt;set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"&gt; &lt;translate android:fromXDelta="0%" android:toXDelta="-100%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="1400"/&gt; &lt;/set&gt; **out_to_right.xml** &lt;set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"&gt; &lt;translate android:fromXDelta="0%" android:toXDelta="100%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="1400"/&gt; &lt;/set&gt; </code></pre>
 

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