Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to marquee images in android (automatically)?

I want to have the marquee functionality available in html in my android application.I don't know what do we call it in android.

for example,I have four to five images.they need be marquee either from left to right or from right to left.(automatically)

1 note-I am not asking about Horizontal scroll view.

What is the procedure and How can i get this feature?

like image 712
elegance Avatar asked Mar 01 '13 13:03

elegance


2 Answers

I GOT THE ANSWER...FOR MY QUESTION

ITS AUTOSLIDER

 public class AutoSlider extends Activity {

    public int currentimageindex=0;
    Timer timer;
    TimerTask task;
    ImageView slidingimage;

    int[] IMAGE_IDS = {R.drawable.image1, R.drawable.image2, R.drawable.image3,
            R.drawable.image4};

    @Override
    protected void onCreate(Bundle savedInstanceState) 
{
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
        final Handler mHandler = new Handler();

        // Create runnable for posting
        final Runnable mUpdateResults = new Runnable() {
            public void run() {

                AnimateandSlideShow();

            }
        };

        int delay = 1000; // delay for 1 sec.

        int period = 8000; // repeat every 4 sec.

        Timer timer = new Timer();

        timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {

             mHandler.post(mUpdateResults);

        }

        }, delay, period);

    }

    public void onClick(View v) {

        finish();
        android.os.Process.killProcess(android.os.Process.myPid());
      }
       private void AnimateandSlideShow() {

        slidingimage = (ImageView)findViewById(R.id.ImageView_id);
        slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);

        currentimageindex++;

      }

}

and in your XML have just the layout and the image view with its width,height and position.

like image 181
elegance Avatar answered Oct 18 '22 07:10

elegance


You can use the View Pager along with the Timer: On each time tick change the page of the view pager using pager adapter:

Official defination of View pager:

Layout manager that allows the user to flip left and right through pages of data. You supply an implementation of a PagerAdapter to generate the pages that the view shows

Please look at some examples of View pager and view flippers :

http://www.edumobile.org/android/android-beginner-tutorials/view-pager-example-in-android-development/

http://wptrafficanalyzer.in/blog/image-slideshow-using-viewflipper-in-android/ (Using view flipper)

like image 27
Karan_Rana Avatar answered Oct 18 '22 09:10

Karan_Rana