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. K2 BPM+Microsoft Dynamics CRM,妥妥的~

    啊~~~~七夕 ▼ 你比巴西少一xi 你比山西多四xi 对有情人来说今天就是情人节,对单身汪来说,今天就是个星期四. but,软件也是要秀恩爱的! ♥ 晒晒我家亲爱的CRM,它的全名叫Microsof ...

  2. Spring学习笔记之BeanFactory

    Spring bean container 的根接口,也是一个bean容器的基本功能,更深一步的接口像ListableBeanFactory 和 ConfigurableBeanFactory 都是 ...

  3. source 命令与“ . ”点命令

    http://wenku.baidu.com/link?url=r3_WjJwQziv5wooIiatYbIMotPHcop56ZyakNGFor5DgJLQD-orAwVmOwp80RAnJ3tRD ...

  4. 教学目标的表述方式──行为目标的ABCD表述法

    教学目标应规定学生在教学活动结束后能表现出什么样的学业行为,并限定学生学习过程中知识.技能的获得和情感态度发展的层次.范围.方式及变化效果的量度.对每节课教学目标的准确表述,可以充分发挥教学目标在教学 ...

  5. Oracle 12c与GoldenGate 12c的一些问答

    1. 如何知道一个12c DB是否为容器数据库?(1) container DBSQL> select cdb from v$database;CDB---YES (2) non contain ...

  6. 系统的 host文件的作用

    有些用户可能已经注意到,我们在上网时除了可使用常规的 http://www.xxx.com或http://www.xxx.com.cn等形式的网站域名之外,还可以使用类似于“202.106.184.2 ...

  7. malloc,vmalloc与kmalloc,kfree与vfree的区别和联系

    kmalloc和vmalloc是分配的是内核的内存,malloc分配的是用户的内存kmalloc保证分配的内存在物理上是连续的,vmalloc保证的是在虚拟地址空间上的连续kmalloc能分配的大小有 ...

  8. (转)js的左右滑动触屏事件

    原文:http://blog.sina.com.cn/s/blog_6a0a183f0100zsfk.html (2012-01-20 08:55:53) 转载▼ 标签: 移动设备 触屏事件 杂谈 分 ...

  9. hdu 2049

    Ps:WA了无限次...简直做到崩溃..高中学的知识都忘了....这道题就是跟2048差不多.. 从N个人里选M个人,有Cmn种选法,然后就是M的错排*Cnm 代码: #include "s ...

  10. Python的交互式界面 编写 .

    from tkinter import * # 导入tkinter模块的所有内容 root = Tk() # 创建一个文本Label对象 textLabel = Label(root, # 将内容绑定 ...