Android开发案例 设置背景图片轮播
点击按钮实现图片轮播效果
实践案例:

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);
}
});
}
}
Android开发案例 设置背景图片轮播的更多相关文章
- Android 开发最牛的图片轮播控件,基本什么都包含了。
Android图片轮播控件 源码下载地址: Android 图片轮播 现在的绝大数app都有banner界面,实现循环播放多个广告图片和手动滑动循环等功能.因为ViewPager并不支持循环翻页, ...
- Hexo瞎折腾系列(2) - 添加背景图片轮播
动态背景图片插件jquery-backstretch jquery-backstretch是一款简单的jQuery插件,可以用来设置动态的背景图片,以下是官方网站的介绍. A simple jQuer ...
- Android代码中设置背景图片
//设置背景图片 String picfile= Environment.getExternalStorageDirectory() + "/pdp/pdp.png" ...
- Android开发实战之ViewPager的轮播
在安卓开发的许多控件中,如果你没有使用过ViewPager,就不能算是一个安卓开发工程师,在本篇博文中,我会总结ViewPager的使用方法, 以及一些开发中的拓展.希望本篇博文对你的学习和工作有所帮 ...
- android 项目中设置背景图片
xml文件设置背景图片中:任意一个控件,button imageView 或layout,在其的xml属性设置中,添加 [XML] view plaincopy android:background= ...
- Android学习笔记之图片轮播...
PS:一个bug又折腾了一个下午....哎... 学习内容: 1.Android利用ViewPager和PagerAdapter实现图片轮播... 2.使用反射机制获取Android的资源信息... ...
- Android 使用ViewPager 做的半吊子的图片轮播
Android 使用ViewPager 做的半吊子的图片轮播 效果图 虽然不咋样,但是最起码的功能是实现了,下面我们来一步步的实现它. 界面 下面我们来分析一下界面的构成 整体的布局: 因为我们要做出 ...
- Android开发(九)——ViewFlipper实现图片轮播
图片轮播的实现方法有很多,主要有View.ViewFilpper.ViewFilpper系统自带的一个多页面管理控件,它可以实现子界面的自动切换. 首先 需要为ViewFlipper加入View (1 ...
- 【iOS开发-55】图片轮播案例:scrollView的分页、滚动栏、利用代理控制定时器和Page Control以及多线程问题
案例: (1)用storyboard布局,这里用了三样东西. --UIScrollView就是我们准备存放滚动图片的容器. --Page Control就是控制页数的那几个小点点.能够设置有多少个点. ...
随机推荐
- Oracle中的job(定时任务)
oracle中的job(定时任务)由dbms_job包下的函数实现.关于job的理论知识可参考https://blog.csdn.net/apextrace/article/details/77675 ...
- Linux基础命令---wget下载工具
wget wget是一个免费的文件下载工具,可以从指定的URL下载文件到本地主机.它支持HTTP和FTP协议,经常用来抓取大量的网页文件. 此命令的适用范围:RedHat.RHEL.Ubuntu.Ce ...
- OC-copy,单例
总结 编号 主题 内容 一 NSFileManager NSFileManager介绍/用法(常见的判断)/文件访问/文件操作 二 集合对象的内存管理 集合对象的内存管理/内存管理总结 三 *copy ...
- activiti工作流引擎
参考文章 Activiti-5.18.0与springMvc项目集成和activiti-explorer单独部署Web项目并与业务数据库关联方法(AutoEE_V2实现方式) https://blog ...
- When should we write our own copy constructor?
Reference:http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html Please write ...
- Linux:while read line与for循环的区别
while read line:是一次性将文件信息读入并赋值给变量line , while中使用重定向机制,文件中的所有信息都被读入并重定向给了整个while 语句中的line 变量. for:是每次 ...
- 【Java 基础】Java 根据Class获取对象实例
Spring在代码中获取bean的几种方式 方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法 ...
- 【力扣】973. 最接近原点的 K 个点
我们有一个由平面上的点组成的列表 points.需要从中找出 K 个距离原点 (0, 0) 最近的点. (这里,平面上两点之间的距离是欧几里德距离.) 你可以按任何顺序返回答案.除了点坐标的顺序之外, ...
- ES 6 新特性笔记
let 与 var 的区别 功能 let var 块级作用域 ️ 变量提升 ️ 重复声明(相同作用域内) ️ var 没有块级作用域的解决方法 使用函数替代块级作用域,以保证变量的正常使用,如: .. ...
- Vue2与Vue3的组件通讯对比
Vue2 父传子 父传子比较简单, 主要通过以下步骤实现 父在template中为子绑定属性 <Child :childData='pMsg'/> <!-- 也可以写死 --> ...