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

Android實現(xiàn)背景圖片輪播

 更新時間:2020年12月22日 11:43:09   作者:明金同學(xué)  
這篇文章主要為大家詳細介紹了Android實現(xiàn)背景圖片輪播,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)背景圖片輪播的具體代碼,供大家參考,具體內(nèi)容如下

點擊按鈕實現(xiàn)圖片輪播效果

實踐案例:

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".Main2Activity"
  android:orientation="vertical"
  android:gravity="center">
 
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="350dp">
 
    <android.support.v7.widget.AppCompatImageView
      android:id="@+id/img1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@mipmap/img1" />
 
    <android.support.v7.widget.AppCompatImageView
      android:id="@+id/img2"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@mipmap/img2" />
 
    <android.support.v7.widget.AppCompatImageView
      android:id="@+id/img3"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@mipmap/img3" />
  </LinearLayout>
 
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <Button
      android:id="@+id/button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:text="切換圖片" />
 
    <Button
      android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:text="返回主頁" />
 
  </LinearLayout>
 
</LinearLayout>

Java

package com.example.administrator.demo2;
 
import android.content.Intent;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
 
public class Main2Activity extends AppCompatActivity {
  //定義所有的輪播圖片
  int[] image = new int[]{
      R.mipmap.img1,
      R.mipmap.img2,
      R.mipmap.img3
  };
  //定義初始下標為0
  int Index = 0;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    //獲取ImageView
    final ImageView img = (ImageView) findViewById(R.id.img1);
    img.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if (Index>=2){
          Index=-1;
        }
        //改變ImageView中的Src屬性值
        img.setImageResource(image[++Index]);
      }
    });
 
    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if (Index>=2)
          Index=-1;
        //改變ImageView中的Src屬性值
        img.setImageResource(image[++Index]);
      }
    });
 
    Button ubt1 = (Button) findViewById(R.id.button2);
    ubt1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent it = new Intent();
        it.setClass(Main2Activity.this,MainActivity.class);
        startActivity(it);
      }
    });
 
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android程序開發(fā)之Fragment實現(xiàn)底部導(dǎo)航欄實例代碼

    Android程序開發(fā)之Fragment實現(xiàn)底部導(dǎo)航欄實例代碼

    流行的應(yīng)用的導(dǎo)航一般分為兩種,一種是底部導(dǎo)航,一種是側(cè)邊欄。本文給大家介紹Fragment實現(xiàn)底部導(dǎo)航欄,對Fragment實現(xiàn)底部導(dǎo)航欄相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧
    2016-03-03
  • Android控件之Gallery用法實例分析

    Android控件之Gallery用法實例分析

    這篇文章主要介紹了Android控件之Gallery用法,以完整實例形式較為詳細的分析了Gallery控件實現(xiàn)圖像顯示的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • 用AdapterViewFlipper輕松完成圖片輪播

    用AdapterViewFlipper輕松完成圖片輪播

    這篇文章主要介紹了如何用AdapterViewFlipper完成圖片輪播,幫助大家更好的理解和學(xué)習(xí)使用AdapterViewFlipper,感興趣的朋友可以了解下
    2021-04-04
  • Android開發(fā)中實現(xiàn)應(yīng)用的前后臺切換效果

    Android開發(fā)中實現(xiàn)應(yīng)用的前后臺切換效果

    這篇文章主要介紹了Android開發(fā)中實現(xiàn)應(yīng)用的前后臺切換效果的方法,文章最后還附帶了監(jiān)聽程序是否進入后臺的判斷方法,需要的朋友可以參考下
    2016-02-02
  • Android Studio 導(dǎo)入新工程項目圖解

    Android Studio 導(dǎo)入新工程項目圖解

    這篇文章主要介紹了Android Studio 導(dǎo)入新工程項目圖解,需要的朋友可以參考下
    2017-12-12
  • Jetpack?Compose狀態(tài)專篇精講

    Jetpack?Compose狀態(tài)專篇精講

    在今年的Google/IO大會上,亮相了一個全新的?Android?原生?UI?開發(fā)框架-Jetpack?Compose,?與蘋果的SwiftIUI一樣,Jetpack?Compose是一個聲明式的UI框架,這篇文章主要介紹了Jetpack?Compose狀態(tài)管理
    2022-10-10
  • Android自定義View實現(xiàn)QQ消息氣泡

    Android自定義View實現(xiàn)QQ消息氣泡

    這篇文章主要為大家詳細介紹了Android自定義View實現(xiàn)QQ消息氣泡,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android使用Intent發(fā)送短信的實現(xiàn)方法

    Android使用Intent發(fā)送短信的實現(xiàn)方法

    這篇文章主要介紹了Android使用Intent發(fā)送短信的實現(xiàn)方法,結(jié)合簡單實例形式分析了Android短信發(fā)送功能的實現(xiàn)技巧,需要的朋友可以參考下
    2016-07-07
  • Android中兩個類讓你再也不用實現(xiàn)onActivityResult()

    Android中兩個類讓你再也不用實現(xiàn)onActivityResult()

    這篇文章主要給大家介紹了關(guān)于Android中兩個類讓你再也不用實現(xiàn)onActivityResult()的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧
    2018-08-08
  • Android編程實現(xiàn)Gallery中每次滑動只顯示一頁的方法

    Android編程實現(xiàn)Gallery中每次滑動只顯示一頁的方法

    這篇文章主要介紹了Android編程實現(xiàn)Gallery中每次滑動只顯示一頁的方法,涉及Android擴展Gallery控件實現(xiàn)翻頁效果控制的功能,涉及Android事件響應(yīng)及屬性控制的相關(guān)技巧,需要的朋友可以參考下
    2015-11-11

最新評論