android change picture every 10 seconds - stack overflow.pdf

Upload: shoaib-quraishi

Post on 28-Feb-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Android Change picture every 10 seconds - Stack Overflow.pdf

    1/5

    Stack Overflow sign up log in

    Questions Tags Users Badges Unanswered Ask

    10 Android Change picture every 10 seconds

    android image

    Im trying to write a very basic android app that displays around 5 pictures one after each other on the screen. I want it to display a different picture afterabout 10 seconds. Can anyone advise me on how I would go around this. Below i have outlined what i would be looking for.

    Picture 1Picture 2Picture 3

    Picture 4Picture 5

    display full screen Picture 1wait 10 secondsRemove Picture 1 and Display Picture 2Wait 10 secondsRemove Picture 2 and Display Picture 3Wait 10 secondsRemove Picture 3 and Display Picture 4Wait 10seconds

    Remove Picture 4 and Display Picture 5Wait 10 seconds

    Start again

    Read this post in our app!

    share improve this question

    http://stackoverflow.com/questions/tagged/androidhttp://stackoverflow.com/questions/tagged/imagehttp://stackoverflow.com/questions/6125936/android-change-picture-every-10-secondshttp://stackexchange.com/http://stackoverflow.com/http://stackexchange.com/http://stackoverflow.com/http://stackoverflow.com/posts/6125936/edithttp://stackoverflow.com/q/6125936http://stackexchange.com/http://stackoverflow.com/questions/tagged/imagehttp://stackoverflow.com/questions/tagged/androidhttp://stackoverflow.com/questions/6125936/android-change-picture-every-10-secondshttp://stackoverflow.com/questions/askhttp://stackoverflow.com/unansweredhttp://stackoverflow.com/help/badgeshttp://stackoverflow.com/usershttp://stackoverflow.com/tagshttp://stackoverflow.com/questionshttps://stackoverflow.com/users/login?ssrc=head&returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f6125936%2fandroid-change-picture-every-10-secondshttps://stackoverflow.com/users/signup?ssrc=head&returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f6125936%2fandroid-change-picture-every-10-secondshttp://stackoverflow.com/
  • 7/25/2019 Android Change picture every 10 seconds - Stack Overflow.pdf

    2/5

    4 Answers Order By Votes

    AskedMay 25 '11 at 14:21

    Marty Cochrane

    364

    2

    5

    22

    30Have you considered using Frame Animations?

    You can specify an xml in your anim folder that contains a frame-by-frame animation, specifing each image duration, and other settings, check

    it out

    UPDATE

    You can also build a frame animation programmatically of course:

    AnimationDrawable animation = new AnimationDrawable();animation.addFrame(getResources().getDrawable(R.drawable.image1), 100);animation.addFrame(getResources().getDrawable(R.drawable.image2), 500);animation.addFrame(getResources().getDrawable(R.drawable.image3), 300);animation.setOneShot(false);

    ImageView imageAnim = (ImageView) findViewById(R.id.img);imageAnim.setBackgroundDrawable(animation);

    // start the animation!animation.start()

    thanks, that worked really well, im an android novice and im programming something for a tablet using 3.1 when i run the app on my virtual android device it brings up a much smaller screenin like portrait is there anyway to fix this and is there any easy way to make an image view fill the screen? Thankyou so much Marty Cochrane May 25 '11 at 16:53

    try putting this on the ImageView xml properties: android:layout_width="fill_parent" android:layout_height="fill_parent". And then set also the android:scaleType property with the value youneed. Look at this link: android-developers.blogspot.com/2009/03/ BFilMay 25 '11 at 17:01

    Works good @BFil. Thanks!!! groff07Oct 24 '13 at 12:50

    share improve this answer

    AnsweredMay 25 '11 at 14:28

    BFil

    8,354

    3

    28

    40

    http://stackoverflow.com/users/380425/bfilhttp://stackoverflow.com/users/380425/bfilhttp://stackoverflow.com/posts/6126031/edithttp://stackoverflow.com/a/6126031http://stackoverflow.com/users/2414975/groff07http://stackoverflow.com/users/380425/bfilhttp://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.htmlhttp://stackoverflow.com/users/589880/marty-cochranehttp://developer.android.com/guide/topics/resources/animation-resource.html#Framehttp://stackoverflow.com/users/589880/marty-cochranehttp://stackoverflow.com/users/589880/marty-cochrane
  • 7/25/2019 Android Change picture every 10 seconds - Stack Overflow.pdf

    3/5

    add a comment

    6you can use the CountDownTimer: follow these steps :

    1) declare an arraywhich will contain the identifients of your pictures

    2 ) declare the CountDownTimerlike this :

    int i=0;new CountDownTimer(10000,1000) {

    @Overridepublic void onTick(long millisUntilFinished) {}

    @Overridepublic void onFinish() {

    imgView.setImageDrawable(sdk.getContext().getResources().getDrawable(array[i]));i++;if(i== array.length-1) i=0;start();

    }}.start();

    This worked. Thank you so much. Dog LoverMay 20 '15 at 7:40

    add a comment

    share improve this answer

    AnsweredMay 25 '11 at 14:41

    Houcine

    12.7k

    8

    36

    68

    EditedJan 19 '13 at 12:36

    2Create a Runnablethat executes the change you want (I suppose it will be changing an ImageView's bitmap/drawable), and post them with delayto the main thread loop, using a Handlerand its postDelayed()method.

    To make it a loop, you could have the runnable post itself.

    http://developer.android.com/reference/android/os/Handler.html#postDelayed%28java.lang.Runnable,%20long%29http://developer.android.com/reference/java/lang/Runnable.htmlhttp://stackoverflow.com/posts/6126261/revisionshttp://stackoverflow.com/users/704513/houcinehttp://stackoverflow.com/users/704513/houcinehttp://stackoverflow.com/posts/6126261/edithttp://stackoverflow.com/a/6126261http://stackoverflow.com/users/4679946/dog-lover
  • 7/25/2019 Android Change picture every 10 seconds - Stack Overflow.pdf

    4/5

    Your Answer

    share improve this answer

    AnsweredMay 25 '11 at 14:28

    bigstones

    11.8k

    3

    42

    69

    EditedMay 25 '11 at 14:38

    1create blink.xml

    put blink.xml in drawable folder and in activity Code write this.

    ImageView mImageView ;mImageView = ( ImageView)findViewById(R.id.imageView); //this is your imageViewmImageView .setImageDrawable(getResources().getDrawable( R.drawable.blink));

    then you will get what you want.!

    This one is cleaner Jason ChuehAug 10 '15 at 1:00

    add a comment

    share improve this answer

    AnsweredApr 22 '15 at 15:26

    Devon

    1,188

    9

    18

    EditedAug 7 '15 at 0:36

    Ardalan Shahgholi

    2,844

    8

    49

    78

    http://stackoverflow.com/users/2063547/ardalan-shahgholihttp://stackoverflow.com/users/2063547/ardalan-shahgholihttp://stackoverflow.com/posts/29802147/revisionshttp://stackoverflow.com/users/879730/devonhttp://stackoverflow.com/users/879730/devonhttp://stackoverflow.com/posts/29802147/edithttp://stackoverflow.com/a/29802147http://stackoverflow.com/users/3538373/jason-chuehhttp://stackoverflow.com/posts/6126039/revisionshttp://stackoverflow.com/users/503900/bigstoneshttp://stackoverflow.com/users/503900/bigstoneshttp://stackoverflow.com/posts/6126039/edithttp://stackoverflow.com/a/6126039
  • 7/25/2019 Android Change picture every 10 seconds - Stack Overflow.pdf

    5/5

    Post Your Answer

    log in

    or

    Name

    Email

    By posting your answer, you agree to theprivacy policyand terms of service.

    meta chat tour help blog privacy policy legal contact us full site

    Download the Stack Exchange Android app

    2016 Stack Exchange, Inc

    https://play.google.com/store/apps/details?id=com.stackexchange.marvinhttp://stackoverflow.com/contacthttp://stackexchange.com/legalhttp://stackexchange.com/legal/privacy-policyhttp://blog.stackoverflow.com/http://stackoverflow.com/helphttp://stackoverflow.com/tourhttp://chat.stackoverflow.com/http://meta.stackoverflow.com/http://stackexchange.com/legal/terms-of-servicehttp://stackexchange.com/legal/privacy-policyhttp://stackoverflow.com/users/login?returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f6125936%2fandroid-change-picture-every-10-seconds