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. This absolute uri http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

    部署生产环境出现以上错误,原因是jsp页面中使用了jstl的标签,但没有导入相应的jar包.因为开发环境 myeclipse10 自带类库已经集成 解决方法 ①将jstl.jar和standard.j ...

  2. IntelliLock托管代码保护和许可授权管理系统软件详细介绍及下载

    IntelliLock是一个能用于控件与应用程序许可授权的100%托管的先进解决方案.与.NET Reactor提供的基于源代码保护的授权许可系统不同,IntelliLock选择了以100%托管的方式 ...

  3. idea快捷键(转)

    Ctrl+/ 或 Ctrl+Shift+/ 注释(// 或者/*...*/ )Ctrl+D 复制行Ctrl+X 删除行快速修复 alt+enter (modify/cast)代码提示 alt+/ctr ...

  4. C# CsvFile 类

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  5. 转 15款免费WiFi(入侵破解)安全测试工具

    转:http://www.ctocio.com/security/cloudsecurity/6594.html 一.Vistumbler扫描器 WiFi 扫描器能能发现附近AP的详细信息,例如信号强 ...

  6. WPF制作子窗体的弹出动画效果

    创建一个WPF应用程序WpfApplication1,新建个窗体DialogWin <Windowx:Class="WpfApplication1.DialogWin" xm ...

  7. windows8.1 plsql连接oracle

    http://pan.baidu.com/share/link?shareid=3782452820&uk=3557941237 http://pan.baidu.com/share/link ...

  8. FR #3题解

    A. 傻逼题?...前缀和什么的随便搞搞就好了. #include<iostream> #include<cstdio> #include<cstring> #in ...

  9. js实现图片预显示

    html页面代码 <div id="localImag" style="display:none"><img  id="previe ...

  10. iOS9的适配

    1.大部分社交平台接口不支持https协议. 问题描述:在iOS9下,系统默认会拦截对http协议接口的访问,因此无法获取http协议接口的数据.对ShareSDK来说,具体表现可能是,无法授权.分享 ...