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í)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Android基于AdapterViewFlipper實現(xiàn)的圖片/文字輪播動畫控件
- Android輪播圖點擊圖片放大效果的實現(xiàn)方法
- Android實現(xiàn)圖片輪播列表
- 詳解android 視頻圖片混合輪播實現(xiàn)
- Android開發(fā)實現(xiàn)的自動換圖片、輪播圖效果示例
- Android實現(xiàn)輪播圖片展示效果
- Android自定義圖片輪播Banner控件使用解析
- Android高級圖片滾動控件實現(xiàn)3D版圖片輪播器
- Android開發(fā)使用Handler的PostDelayed方法實現(xiàn)圖片輪播功能
- 用AdapterViewFlipper輕松完成圖片輪播
相關(guān)文章
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-03Android開發(fā)中實現(xiàn)應(yīng)用的前后臺切換效果
這篇文章主要介紹了Android開發(fā)中實現(xiàn)應(yīng)用的前后臺切換效果的方法,文章最后還附帶了監(jiān)聽程序是否進入后臺的判斷方法,需要的朋友可以參考下2016-02-02Android使用Intent發(fā)送短信的實現(xiàn)方法
這篇文章主要介紹了Android使用Intent發(fā)送短信的實現(xiàn)方法,結(jié)合簡單實例形式分析了Android短信發(fā)送功能的實現(xiàn)技巧,需要的朋友可以參考下2016-07-07Android中兩個類讓你再也不用實現(xiàn)onActivityResult()
這篇文章主要給大家介紹了關(guān)于Android中兩個類讓你再也不用實現(xiàn)onActivityResult()的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧2018-08-08Android編程實現(xiàn)Gallery中每次滑動只顯示一頁的方法
這篇文章主要介紹了Android編程實現(xiàn)Gallery中每次滑動只顯示一頁的方法,涉及Android擴展Gallery控件實現(xiàn)翻頁效果控制的功能,涉及Android事件響應(yīng)及屬性控制的相關(guān)技巧,需要的朋友可以參考下2015-11-11