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);
        }
    
    
        }
  • 相关阅读:
    C#判断网络链接状态
    C# 创建临时文件(转帖)
    C# 很久以前几个常用类
    正则附表
    如何判断WebBrowser浏览器网页加载完成
    控件阴影
    C# 使用WM_COPYDATA传输数据(两个窗体间通信)
    C# 调用POST请求
    改变无边框窗体的尺寸大小和移动无边框窗体
    IT学习网站
  • 原文地址:https://www.cnblogs.com/youshashuosha/p/5370392.html
Copyright © 2011-2022 走看看