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

Android控件ImageSwitcher實(shí)現(xiàn)左右圖片切換功能

 更新時(shí)間:2022年05月17日 09:51:06   作者:summerpxy  
這篇文章主要為大家詳細(xì)介紹了Android控件ImageSwitcher實(shí)現(xiàn)左右圖片切換功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

ImageSwitcher類是ViewSwitcher類的子類,它實(shí)現(xiàn)的效果是在完成ImageView的切換并且?guī)в袆?dòng)畫(huà)效果。要使用這個(gè)類需要以下兩個(gè)步驟:

1)為ImageSwitcher類提供一個(gè)ViewFactory,該ViewFactory生成的View組件必須是ImageView。

2)需要切換的時(shí)候,只需要嗲用ImageSwitcher的setImageDrawable()、setImageResource()、setImageURL()方法即可實(shí)現(xiàn)切換。

activity_main.xml:

<LinearLayout 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:orientation="vertical"
  tools:context=".MainActivity" >

  <ImageSwitcher
    android:id="@+id/imageswitcher"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_gravity="center_horizontal" />

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <Button
      android:id="@+id/back"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:text="back" />

    <Button
      android:id="@+id/forward"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
      android:text="forward" />
  </RelativeLayout>

</LinearLayout>

Main_activity.java:

package com.example.android_imageswitcher1;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;

public class MainActivity extends Activity implements ViewFactory,
    OnClickListener {

  ImageSwitcher mImageSwitcher = null;
  Button btn1, btn2;
  int index = 0;
  int[] resId = new int[9];

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mImageSwitcher = (ImageSwitcher) this.findViewById(R.id.imageswitcher);
    btn1 = (Button) this.findViewById(R.id.back);
    btn2 = (Button) this.findViewById(R.id.forward);
    btn1.setOnClickListener(this);
    btn2.setOnClickListener(this);
    mImageSwitcher.setFactory(this);
    mImageSwitcher.setInAnimation(this, android.R.anim.slide_in_left);
    mImageSwitcher.setOutAnimation(this, android.R.anim.slide_out_right);
    initResources();
    if (resId.length > 0) {
      mImageSwitcher.setImageResource(resId[0]);
    }
  }

  public void initResources() {
    resId[0] = R.drawable.adobe;
    resId[1] = R.drawable.android;
    resId[2] = R.drawable.circle;
    resId[3] = R.drawable.digg;
    resId[4] = R.drawable.flower;
    resId[5] = R.drawable.gmail;
    resId[6] = R.drawable.imdb;
    resId[7] = R.drawable.photo;
    resId[8] = R.drawable.point;
  }

  @Override
  public View makeView() {
    return new ImageView(MainActivity.this);
  }

  @Override
  public void onClick(View view) {
    int action = view.getId();
    switch (action) {
    case R.id.back:
      index--;
      if (index < 0) {
        index = resId.length - 1;
      }
      mImageSwitcher.setImageResource(resId[index]);
      break;
    case R.id.forward:
      index++;
      if (index > resId.length - 1) {
        index = 0;
      }
      mImageSwitcher.setImageResource(resId[index]);
      break;
    default:
      break;
    }

  }

}

實(shí)現(xiàn)的效果如下:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)Android軟件編程有所幫助。

相關(guān)文章

  • Android的HTTP擴(kuò)展包OkHttp中的緩存功能使用方法解析

    Android的HTTP擴(kuò)展包OkHttp中的緩存功能使用方法解析

    OkHttp(GitHub主頁(yè)https://github.com/square/okhttp)是一款高人氣的第三方Android網(wǎng)絡(luò)編程包,這里我們來(lái)看一下Android的HTTP擴(kuò)展包OkHttp中的緩存功能使用方法解析:
    2016-07-07
  • activity控制對(duì)話框風(fēng)格、顯示大小與位置

    activity控制對(duì)話框風(fēng)格、顯示大小與位置

    對(duì)于對(duì)話框風(fēng)格大家普遍使用PopupWindow,也有許多朋友開(kāi)發(fā)設(shè)計(jì)時(shí)使用的是activity對(duì)話框方式,因此,本文對(duì)如何通過(guò)activity實(shí)現(xiàn)與PopupWindow相同的效果進(jìn)行詳細(xì)介紹,具有很好的參考價(jià)值,需要的朋友一起來(lái)看下吧
    2016-12-12
  • 解決Android平臺(tái)中應(yīng)用程序OOM異常的方法

    解決Android平臺(tái)中應(yīng)用程序OOM異常的方法

    這篇文章主要介紹了解決Android平臺(tái)中應(yīng)用程序OOM異常的方法,通常這一塊也是程序中的重點(diǎn)之一,感興趣的小伙伴們可以參考一下
    2015-12-12
  • Android實(shí)現(xiàn)花瓣飄落效果的步驟

    Android實(shí)現(xiàn)花瓣飄落效果的步驟

    這篇文章主要介紹了Android實(shí)現(xiàn)花瓣飄落效果的步驟,幫助大家更好的理解和學(xué)習(xí)使用Android開(kāi)發(fā),感興趣的朋友可以了解下
    2021-04-04
  • Android RIL使用詳解

    Android RIL使用詳解

    這篇文章主要介紹了Android RIL使用詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • android popuwindow點(diǎn)擊外部窗口不消失的實(shí)例

    android popuwindow點(diǎn)擊外部窗口不消失的實(shí)例

    下面小編就為大家?guī)?lái)一篇android popuwindow點(diǎn)擊外部窗口不消失的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-04-04
  • Android畫(huà)圖之抗鋸齒paint和Canvas兩種方式實(shí)例

    Android畫(huà)圖之抗鋸齒paint和Canvas兩種方式實(shí)例

    本篇文章主要介紹了Android畫(huà)圖之抗鋸齒paint和Canvas兩種方式實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android BannerView通用封裝詳解

    Android BannerView通用封裝詳解

    這篇文章主要介紹了Android BannerView通用封裝詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • Android VideoCache視頻緩存的方法詳解

    Android VideoCache視頻緩存的方法詳解

    這篇文章主要介紹了Android VideoCache視頻緩存的方法詳解的相關(guān)資料,AndroidVideoCache是一個(gè)視頻/音頻緩存庫(kù),利用本地代理實(shí)現(xiàn)了邊下邊播,需要的朋友可以參考下
    2017-07-07
  • Android實(shí)現(xiàn)過(guò)渡動(dòng)畫(huà)、引導(dǎo)頁(yè) Android判斷是否第一次啟動(dòng)App

    Android實(shí)現(xiàn)過(guò)渡動(dòng)畫(huà)、引導(dǎo)頁(yè) Android判斷是否第一次啟動(dòng)App

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)過(guò)渡動(dòng)畫(huà)、引導(dǎo)頁(yè),以及Android判斷是否第一次啟動(dòng)App,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12

最新評(píng)論