Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8682215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:42:46+00:00 2026-06-12T21:42:46+00:00

activity_main.xml : <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=horizontal > <ViewFlipper android:layout_margin=6dip android:id=@+id/view_flipper android:layout_width=wrap_content android:layout_height=wrap_content> <ImageView

  • 0

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ViewFlipper
        android:layout_margin="6dip"
        android:id="@+id/view_flipper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">           

        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/photo1"/>        

        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/photo2"/>

        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/photo3"/>

        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/photo4"/>


    </ViewFlipper>

</LinearLayout>

MainActivity:

public class MainActivity extends Activity {

    private ViewFlipper vf; 
    private float lastX;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        vf = (ViewFlipper) findViewById(R.id.view_flipper);        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public boolean onTouchEvent(MotionEvent touchevent) {

        switch (touchevent.getAction())
        {
            case MotionEvent.ACTION_DOWN:
            {
                lastX = touchevent.getX();
                break;
            }

            case MotionEvent.ACTION_UP:
            {
                float currentX = touchevent.getX();

                if (lastX < currentX)
                {
                    if (vf.getDisplayedChild()==0) 
                        break;

                    vf.setInAnimation(this, R.anim.in_from_left);
                    vf.setOutAnimation(this, R.anim.out_to_right);
                    vf.showNext();
                }

                if (lastX > currentX)
                {
                    if (vf.getDisplayedChild()==1) 
                        break;

                    vf.setInAnimation(this, R.anim.in_from_right);  
                    vf.setOutAnimation(this, R.anim.out_to_left);
                    vf.showPrevious();                  
                }

                break;
            }

            case MotionEvent.ACTION_MOVE:
            {
                float tempX = touchevent.getX();
                int scrollX = (int) (tempX - lastX);

                //vf.scrollBy(scrollX, 0);

                break;
            }

        }

        return false;

    }
}

Order of images goes like this: photo1, photo4, photo3, photo2. How to make it: photo1, photo2, photo3, photo4?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:42:49+00:00Added an answer on June 12, 2026 at 9:42 pm

    The order of the images are alright, but there is something wrong with your code. See below how to fix the issue:

    public class MainActivity extends Activity {
    
        private ViewFlipper vf;
        private float lastX;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            vf = (ViewFlipper) findViewById(R.id.view_flipper);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    
        public boolean onTouchEvent(MotionEvent touchevent) {
    
            switch (touchevent.getAction())
            {
                case MotionEvent.ACTION_DOWN:
                {
                    lastX = touchevent.getX();
                    break;
                }
    
                case MotionEvent.ACTION_UP:
                {
                    float currentX = touchevent.getX();
    
                    if (lastX < currentX)
                    {
                        if (vf.getDisplayedChild()==0)
                            break;
    
                        vf.setInAnimation(this, R.anim.in_from_left);
                        vf.setOutAnimation(this, R.anim.out_to_right);
    //                    vf.showNext();
                        vf.showPrevious();
                    }
    
                    if (lastX > currentX)
                    {
    //                    if (vf.getDisplayedChild()==1)
                        if (vf.getDisplayedChild()==vf.getChildCount()-1)
                            break;
    
                        vf.setInAnimation(this, R.anim.in_from_right);
                        vf.setOutAnimation(this, R.anim.out_to_left);
    //                    vf.showPrevious();
                        vf.showNext();
                    }
    
                    break;
                }
    
                case MotionEvent.ACTION_MOVE:
                {
                    float tempX = touchevent.getX();
                    int scrollX = (int) (tempX - lastX);
    
                    //vf.scrollBy(scrollX, 0);
    
                    break;
                }
    
            }
    
            return false;
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

main.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical android:padding=10dp android:background=@drawable/gradientbg > <android.support.v4.view.ViewPager android:layout_width=match_parent
Please have a look at the following code activity_main.xml <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools android:layout_width=match_parent android:layout_height=match_parent
Main.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent > <Spinner android:layout_width=wrap_content android:layout_height=wrap_content android:id=@+id/spin
Please have a look at the following code activity_main.xml <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools android:layout_width=match_parent android:layout_height=match_parent
I am new to android. I created a main.xml file like <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
here is my layuout main.xml ; <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent>
My main.xml looks like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent >
i am having my manifest file like this <manifest xmlns:android=http://schemas.android.com/apk/res/android package=com.basic.adwhrilsample android:versionCode=1 android:versionName=1.0 >
Im using this guide to implement a ViewPager : http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/ This is my main.xml
I am trying to implement this example http://www.javacodegeeks.com/2011/02/android-google-maps-tutorial.html and i have followed exactly all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.