繁体   English   中英

如何在android中背靠背4图像闪烁图像

[英]How to blink image in back to back 4 image in android

我想要背对背闪烁4张图像。 这意味着1个图像显示n消失,当第1个图像消失时显示第2个图像,当第2个图像消失时显示第3个图像,此过程继续按照我的要求,图像在运行时加载。

如果图像是基于网址或上网的话

int pos=0;
    String[] urlsOfimages;

     private Handler blnkHandler = new Handler() {

          public void handleMessage(Message msg) {
           switch(msg.what) {
           case STOPSPLASH:
               //Set image here form the urlsOfimages[pos]
            img.setVisibility(ImageView.GONE);
            resumeMessage = new Message();
            resumeMessage.what = RESUMESPLASH;
            resumeHandler.sendMessageDelayed(resumeMessage, SPLASHTIME);

            pos++;

//Logic could be improve by your self by sending What pram, i just give you and idea
            if(pos==5)
                pos=0;

           }
          }
         };

         private Handler resumeHandler = new Handler() {

          public void handleMessage(Message msg) {
           switch(msg.what) {
           case RESUMESPLASH:
            img.setVisibility(ImageView.VISIBLE);
            stopMessage.what = STOPSPLASH;
            blnkHandler.sendMessageDelayed(stopMessage, SPLASHTIME);
           }
          }
         };

并在创建方法

blnkHandler.sendMessageDelayed(STOPSPLASH, SPLASHTIME);

如果图像在可绘制文件夹中可脱机,则

AnimationDrawable myAnimationDrawable;
    public void loadAnimation()
    {
        ImageView myAnimation = (ImageView)findViewById(R.id.progress_bar);
         myAnimationDrawable= (AnimationDrawable)myAnimation.getDrawable();
        myAnimationDrawable.start();        
    }

在XML中像anim_loading.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list android:id="@+id/progress_horizontal" android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/loading_0" android:duration="500" />
        <item android:drawable="@drawable/loading_1" android:duration="500" />
        <item android:drawable="@drawable/loading_2" android:duration="500" />
        <item android:drawable="@drawable/loading_3" android:duration="500" />
        <item android:drawable="@drawable/loading_4" android:duration="500" />
     </animation-list> 

如果必须在运行时选择图像,则将语法创建为动画列表

    animation = new AnimationDrawable();
    animation.addFrame(getResources().getDrawable(R.drawable.img1), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.img2), 1000);
    animation.addFrame(getResources().getDrawable(R.drawable.img3), 1000);
    animation.setOneShot(false);

    ImageView imageAnim =  (ImageView) findViewById(R,id.img);
    imageAnim.setBackgroundDrawable(animation);
    imageAnim.post(new Runnable() {

        @Override
        public void run() {
            animation.start();   
        }
    });

尝试以下代码: -

     private void loadingAmin(final TextView loading) {

            final Animation pokeLoadingAnim = new Animation() {

                    int step = 0;

                    @Override
                    protected void applyTransformation(float interpolatedTime,
                                    Transformation t) {
                            // TODO Auto-generated method stub
                            super.applyTransformation(interpolatedTime, t);
                            if (interpolatedTime == 0) {
                                    loading.setText("Loading");
                                    step = 1;
                            }
                            if ((interpolatedTime / 0.3) > step) {
                                    loading.setText(loading.getText() + ".");
                                    ++step;
                            }

                    }
            };
            pokeLoadingAnim.setDuration(2000);
            pokeLoadingAnim.setRepeatCount(Animation.INFINITE);
            pokeLoadingAnim.setInterpolator(new LinearInterpolator());
            pokeLoadingAnim.setRepeatMode(Animation.RESTART);
            loading.startAnimation(pokeLoadingAnim);
    }

叫这个方法

            TextView layout = (TextView) getView().findViewById(R.id.loading);
            loadingAmin(layout);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM