zoukankan      html  css  js  c++  java
  • Android · 广告走灯

    layout

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/rl"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="fill_parent"
            android:layout_height="120dp"
            android:background="@drawable/icon" />
    
        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="fill_parent"
            android:layout_height="120dp"
            android:background="@drawable/expriment" />
    
    
    </RelativeLayout>

    MainActivity

    package com.manhua.imagead;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.util.Log;
    import android.view.animation.Animation;
    import android.view.animation.AnimationSet;
    import android.view.animation.TranslateAnimation;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
    
        public ImageView imageView;
        public ImageView imageView2;
    
        public Animation animation1;
        public Animation animation2;
        
        public boolean juage = true;
    
        public int images[] = new int[] { R.drawable.icon, R.drawable.expriment,
                R.drawable.changer, R.drawable.dataline, R.drawable.preffitication };
    
        public int count = 0;
        
        public Handler handler = new Handler();
    
        public Runnable runnable = new Runnable() {
    
            @Override
            public void run() {
                // TODO Auto-generated method stub
                AnimationSet animationSet1 = new AnimationSet(true);
                AnimationSet animationSet2 = new AnimationSet(true);
                imageView2.setVisibility(0);
                TranslateAnimation ta = new TranslateAnimation(
                        Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
                        -1f, Animation.RELATIVE_TO_SELF, 0f,
                        Animation.RELATIVE_TO_SELF, 0f);
                ta.setDuration(2000);
                animationSet1.addAnimation(ta);
                animationSet1.setFillAfter(true);
                ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f,
                        Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
                        0f, Animation.RELATIVE_TO_SELF, 0f);
                ta.setDuration(2000);
                animationSet2.addAnimation(ta);
                animationSet2.setFillAfter(true);
                
                imageView.startAnimation(animationSet1);
                imageView2.startAnimation(animationSet2);
                imageView.setBackgroundResource(images[count % images.length]);
                count++;
                imageView2.setBackgroundResource(images[count % images.length]);
                
                
                if (juage)
                    handler.postDelayed(runnable, 6000);
                Log.i("handler", "handler");
            }
    
        };
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            imageView = (ImageView) findViewById(R.id.imageView);
            imageView2 = (ImageView) findViewById(R.id.imageView2);
    
            imageView2.setVisibility(4);
            handler.postDelayed(runnable, 2000);
        }
        
    
        public void onPause() {
            juage = false;
            super.onPause();
        }
    
    
    }
  • 相关阅读:
    Linux命令应用大词典-第11章 Shell编程
    Kubernetes 学习12 kubernetes 存储卷
    linux dd命令
    Kubernetes 学习11 kubernetes ingress及ingress controller
    Kubernetes 学习10 Service资源
    Kubernetes 学习9 Pod控制器
    Kubernetes 学习8 Pod控制器
    Kubernetes 学习7 Pod控制器应用进阶2
    Kubernetes 学习6 Pod控制器应用进阶
    Kubernetes 学习5 kubernetes资源清单定义入门
  • 原文地址:https://www.cnblogs.com/manhua/p/4165913.html
Copyright © 2011-2022 走看看