欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)使用Handler實(shí)現(xiàn)圖片輪播功能示例

 更新時(shí)間:2017年09月08日 10:01:29   作者:ITzhongzi  
這篇文章主要介紹了Android開發(fā)使用Handler實(shí)現(xiàn)圖片輪播功能,涉及Android基于Handler操作圖片的相關(guān)實(shí)現(xiàn)技巧與操作注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Android使用Handler實(shí)現(xiàn)圖片輪播功能。分享給大家供大家參考,具體如下:

提前定義好一個(gè)Runnable接口,然后用handler調(diào)用。

Mainactivity代碼如下:

package com.example.handle_01;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
  private TextView textView;
  private Handler handler = new Handler();
  private ImageView imageView;
  private int[]images = {
      R.mipmap.image1,R.mipmap.image2
  };
  private int index;
  private MyRunnable myRunnable = new MyRunnable();
  class MyRunnable implements Runnable{
    @Override
    public void run() {
      index++;
      index = index%2;
      imageView.setImageResource(images[index]);
      handler.postDelayed(myRunnable,1000);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = (TextView) findViewById(R.id.textView);
    imageView = (ImageView) findViewById(R.id.imageView);
    handler.post(myRunnable);
    /*
    new Thread(){
      public void run(){
        try {
          Thread.sleep(1000);
          //post方法xiugai UI
          handler.post(new Runnable() {
            @Override
            public void run() {
              //在UI線程中執(zhí)行
              textView.setText("update thread");
            }
          });
          // textView.setText("update thread");
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }.start();
    */
  }
}

activity_main代碼如下:

<?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.handle_01.MainActivity">
  <TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!" />
  <ImageView
    android:src="@mipmap/ic_launcher"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:layout_centerInParent="true" />
</RelativeLayout>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android雙擊返回鍵退出程序的實(shí)現(xiàn)方法

    Android雙擊返回鍵退出程序的實(shí)現(xiàn)方法

    這篇文章主要介紹了Android雙擊返回鍵退出程序的實(shí)現(xiàn)方法,是Android程序開發(fā)中非常具有實(shí)用價(jià)值的重要技巧,需要的朋友可以參考下
    2014-09-09
  • Android使用shape繪制陰影圖層陰影效果示例

    Android使用shape繪制陰影圖層陰影效果示例

    本篇文章主要介紹了Android使用shape繪制陰影圖層陰影效果示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • 詳解Android JetPack之LiveData的工作原理

    詳解Android JetPack之LiveData的工作原理

    這篇文章主要介紹了詳解Android JetPack之LiveData的工作原理,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下
    2021-03-03
  • 詳解android shape的使用總結(jié)

    詳解android shape的使用總結(jié)

    在Android程序開發(fā)中,我們經(jīng)常會(huì)去用到Shape這個(gè)東西去定義各種各樣的形狀,本篇文章主要介紹了android shape的使用,有興趣的可以一起了解一下。
    2016-12-12
  • Android自定義圓環(huán)倒計(jì)時(shí)控件

    Android自定義圓環(huán)倒計(jì)時(shí)控件

    這篇文章主要為大家詳細(xì)介紹了Android自定義圓環(huán)倒計(jì)時(shí)控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • 詳解Android微信登錄與分享

    詳解Android微信登錄與分享

    本篇文章主要對(duì)Android微信登錄與分享功能的實(shí)現(xiàn)進(jìn)行了介紹。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-01-01
  • Android ListView出現(xiàn)異常解決辦法

    Android ListView出現(xiàn)異常解決辦法

    這篇文章主要介紹了Android ListView出現(xiàn)異常ListView:The content of the adapter has changed but ListView did not receive a notification解決辦法的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • android 為應(yīng)用程序創(chuàng)建桌面快捷方式技巧分享

    android 為應(yīng)用程序創(chuàng)建桌面快捷方式技巧分享

    手機(jī)裝的軟件過多,找起來很不方便,所以在主頁面有一個(gè)快捷方式的話會(huì)很不錯(cuò)的,本文將介紹如何實(shí)現(xiàn),需要了解跟多的朋友可以參考下
    2012-12-12
  • Android實(shí)現(xiàn)ListView左右滑動(dòng)刪除和編輯

    Android實(shí)現(xiàn)ListView左右滑動(dòng)刪除和編輯

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)ListView左右滑動(dòng)刪除和編輯的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-05-05
  • 理解Android中Activity的方法回調(diào)

    理解Android中Activity的方法回調(diào)

    這篇文章主要介紹了理解Android中Activity的方法回調(diào),本文用一個(gè)完整實(shí)例模擬了Activity方法回調(diào)的過程,從而加深理解Activity的方法回調(diào)思想,需要的朋友可以參考下
    2015-04-04

最新評(píng)論