内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

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

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

成都創(chuàng)新互聯(lián)是網(wǎng)站建設專家,致力于互聯(lián)網(wǎng)品牌建設與網(wǎng)絡營銷,專業(yè)領域包括網(wǎng)站制作、成都網(wǎng)站制作、電商網(wǎng)站制作開發(fā)、小程序開發(fā)、微信營銷、系統(tǒng)平臺開發(fā),與其他網(wǎng)站設計及系統(tǒng)開發(fā)公司不同,我們的整合解決方案結合了恒基網(wǎng)絡品牌建設經(jīng)驗和互聯(lián)網(wǎng)整合營銷的理念,并將策略和執(zhí)行緊密結合,且不斷評估并優(yōu)化我們的方案,為客戶提供全方位的互聯(lián)網(wǎng)品牌整合方案!

提前定義好一個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>

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

希望本文所述對大家Android程序設計有所幫助。

網(wǎng)頁題目:Android開發(fā)使用Handler實現(xiàn)圖片輪播功能示例
網(wǎng)頁網(wǎng)址:http://www.rwnh.cn/article30/gsphpo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設計、面包屑導航、軟件開發(fā)、定制網(wǎng)站、網(wǎng)頁設計公司、標簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設
阜南县| 牟定县| 新安县| 奉贤区| 循化| 湖南省| 永善县| 马边| 伊川县| 宿迁市| 大荔县| 花莲县| 陇南市| 扶风县| 奇台县| 化州市| 合江县| 河源市| 鄯善县| 四川省| 景宁| 彰武县| 隆回县| 灯塔市| 镇江市| 临高县| 长子县| 南城县| 浦城县| 新建县| 合江县| 无棣县| 吉林市| 南陵县| 察雅县| 霍山县| 自贡市| 龙川县| 肇庆市| 三门峡市| 呼和浩特市|