zoukankan      html  css  js  c++  java
  • 用Handler图片轮播练习

    XML代码

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.dell.wodelianxi.Tupianlunbo">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/image1"/>
    
    </RelativeLayout>

    JAVA代码

    package com.example.dell.wodelianxi;
    
    import android.os.Handler;
    import android.os.Message;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.ImageView;
    
    import java.util.Timer;
    import java.util.TimerTask;
    
    public class Tupianlunbo extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_tupianlunbo);
            final ImageView image1 = (ImageView) findViewById(R.id.image1);
    
            final int[] imageid = {R.drawable.touxiang1, R.drawable.touxiang2, R.drawable.touxiang13,
                    R.drawable.touxiang14, R.drawable.touxiang15, R.drawable.touxiang16,
                    R.drawable.touxiang17, R.drawable.touxiang18, R.drawable.touxiang19};
            final Handler handler = new Handler() {
                int i = 0;
    
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
    
                    if (msg.what == 1) {
                        image1.setImageResource(imageid[i++ % imageid.length]);
                    }
    
                }
            };
    
           new Timer().schedule(new TimerTask() {
               @Override
               public void run()
               {
                   handler.sendEmptyMessage(1);
               }
           },0,3000);
        }
    
    
        }
  • 相关阅读:
    zookeeper高可用集群搭建
    linux安装配置zookeeper-3.4.10
    hadoop小结
    YARN集群的mapreduce测试(六)
    YARN集群的mapreduce测试(五)
    YARN集群的mapreduce测试(四)
    mxnet卷积神经网络训练MNIST数据集测试
    人脸识别的损失函数
    完全图解RNN、RNN变体、Seq2Seq、Attention机制
    机器学习中的线性和非线性判断
  • 原文地址:https://www.cnblogs.com/youshashuosha/p/5370392.html
Copyright © 2011-2022 走看看