1.看布局文

<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=".MainActivity" > <ImageView
android:id="@+id/imageView1"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:src="@drawable/xiaomi1" /> <ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView1"
android:layout_below="@+id/imageView1"
android:layout_marginLeft="22dp"
android:padding="0dp"
android:src="@drawable/ic_launcher" /> <ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/imageView1"
android:layout_alignTop="@+id/imageButton1"
android:layout_marginRight="17dp"
android:padding="0dp"
android:src="@drawable/ic_launcher" /> </RelativeLayout>

2.activity

package com.example.imagebutton;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView; public class MainActivity extends Activity { private ImageView ivwPicture = null;
private ImageButton ibtnProv = null;
private ImageButton ibtnNext = null;
private Integer Images[] = {R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ivwPicture = (ImageView)this.findViewById(R.id.imageView1);
ibtnProv = (ImageButton)this.findViewById(R.id.imageButton1);
ibtnNext = (ImageButton)this.findViewById(R.id.imageButton2);
ibtnProv.setOnClickListener(new ProvOnClickListener());
ibtnNext.setOnClickListener(new NextOnClickListener()); }
private class ProvOnClickListener implements OnClickListener{
private int i =;
@Override
public void onClick(View v) {
if(i>){
ivwPicture.setImageResource(Images[--i]);
}
else if(i==){
i=;
ivwPicture.setImageResource(Images[]);
}
}
}
private class NextOnClickListener implements OnClickListener{
private int i =;
@Override
public void onClick(View v) {
if(i<){
ivwPicture.setImageResource(Images[i++]);
}
else if(i==){
i=;
ivwPicture.setImageResource(Images[]);
} }
} }

3.运行结果

本文适合有android基础的学习者 学习,所以其中没有加太多备注。因为工作很忙故写文章也写的初略。

android中ImageView讲解的更多相关文章

  1. android中ImageView的ScaleType属性

    android中ImageView的ScaleType属性 ScaleType的值分别代表的意义: ImageView是Android中的基础图片显示控件,该控件有个重要的属性是ScaleType,该 ...

  2. Android中ImageView的属性

    资源使用 Android 中支持三种格式的位图文件:.png(首选), .jpg(可接受),.gif(不建议) 为什么首推 PNG 呢? 官网的描述如下: 注:在构建过程中,可通过 aapt 工具自动 ...

  3. Android中ImageView.ScaleType属性值

    1 android:scaleType="center" (1)当图片大于ImageView的宽高:以图片的中心点和ImageView的中心点为基准,按照图片的原大小居中显示,不缩 ...

  4. android中Imageview的布局和使用

    布局: <ImageView android:id="@+id/imt_photo" android:layout_width="fill_parent" ...

  5. Android 中单位讲解

    1. dip(dp): device independent pixels(设备独立像素). dp也就是dip.这个和sp基本类似.如果设置表示长度.高度等属性时可以使用dp 或sp.但如果设置字体, ...

  6. 怪胎:Android开发ImageView图片无法显示

    今天碰到一个非常奇怪的问题: 在Android中ImageView无法显示加载的本地SDCard图片. 具体过程是:先调用本地照相机程序摄像,然后将拍摄的图片加载在ImageView中显示. publ ...

  7. android 圆角 ImageView

    android中Imageview 内的图片圆角的实现方式 此文针对的是 imageview中图片的圆角, 即忽略掉图片的ScaleType, 均对图片采取圆角.  而不是对Imageview本身的圆 ...

  8. Android开发 - ImageView加载Base64编码的图片

    在我们开发应用的过程中,并不是所有情况下都请求图片的URL或者加载本地图片,有时我们需要加载Base64编码的图片.这种情况出现在服务端需要动态生成的图片,比如: 二维码 图形验证码 ... 这些应用 ...

  9. android中Adapter适配器的讲解

    Adapter(适配器的讲解) 适配器就我自己来看,我觉得这是一个非常重要的知识点,Adapter是用来帮助填出数据的中间桥梁,简单点说吧:将各种数据以合适的形式显示在View中给用户看.Adapte ...

随机推荐

  1. win10系统的点评

    Windows 10 是美国微软公司所研发的新一代跨平台及设备应用的操作系统.在正式版本发布一年内,所有符合条件的Windows7.Windows 8.1的用户都将可以免费升级到Windows 10, ...

  2. java,android获取系统当前时间

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss ");Date curDate = ...

  3. UVa 11020 Efficient Solutions(平衡二叉树/multiset )

    题意:有n个人,每个人有x.y两个属性,每次输入一个人(x,y).如果当前不存在一个人(x`,y`)的属性满足x`<=x,y`<y或者x`<x,y`<=y,就说这个人是有优势的 ...

  4. SQL SERVER中的逻辑读取,物理读取,以及预读的理解

    在SQLSERVER查询分析器中,当我们用Set Statistics on 语句来统计SQL语句或者存储过程I/O的时候, SQLSERVER会显示几个概念去词语:逻辑读取,物理读取,预读. 如下: ...

  5. allegro si(三)

    前言:si的教程市面上是很少的,layout是台湾工程师的强项,还有就是日本人,国人爱用AD. si的教程中靠谱的还是张飞的收费课程,还有华为的资料. Cadence SI 仿真实验步骤如下: 1.熟 ...

  6. Spring中配置文件applicationContext.xml配置详解

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  7. 50元制作PS2键盘无线监控装置

    0×00    什么是Arduino  Arduino实际上就是一种开发板,将微控制器和必需的元件集成在一块电路板上,扩展出完善的接口和针脚,就可以接上各种各样的传感器,完成你心中的设计,你也可以把它 ...

  8. UIControl的使用

    在开发当中,可能很多时候都需要做个点赞的需求,如果用按钮实现,按钮作为一个系统复合控件,外部是一个 View-->UIControl的容器, 内部包含了UILabel和UIImage,以及一些排 ...

  9. 如何调用super

    因此,决定是否调用 super,基于您打算如何重新实施方法: 如果打算补充超类实现的行为,请调用 super. 如果打算替换超类实现的行为,就不要调用 super. 如果您要补充超类行为,另一个需要重 ...

  10. php大力力 [028节] 如何下载js文件,网上一个*.js无法下载啊??????

    php大力力 [028节] 如何下载js文件,网上一个*.js无法下载啊?????? safari也无法下载 迅雷也无法下载 是不是对方网站服务器的不让下载那个js目录的文件??? 只能调用js函数啊 ...