简单的图片浏览器,实现图像显示与点击切换下一张

首先在main.xml里面定义一个简单的线性布局容器。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
> </LinearLayout>

然后在mianactivity.java里面

package org.crazyit.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.view.DragEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnDragListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; public class MainActivity extends Activity {
//定义一个访问图片的数组
int[] images = new int[]{
R.drawable.ic_launcher,
R.drawable.aaa,
R.drawable.asd,
R.drawable.sss };
int currentImg = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取线性布局容器
LinearLayout main = (LinearLayout)findViewById(R.id.root);
//程序创建iamgeview组件
final ImageView image = new ImageView(this);
//添加进布局
main.addView(image);
//初始化显示第一张照片
image.setImageResource(images[0]);
image.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
if (currentImg >=4)
{
currentImg = -1;
}
image.setImageResource(images[++currentImg]);
} });
} }

R.drawable.ic_launcher,
   R.drawable.aaa,
   R.drawable.asd,
   R.drawable.sss

是放在res /drawable里面 的资源图片

定义数组,Int images存放图片id,

currentImg为图片数组的下标,通过它的++,来实现图像读取+1.

android脚步---图片浏览的更多相关文章

  1. Android 高级UI设计笔记14:Gallery(画廊控件)之 3D图片浏览

    1. 利用Gallery组件实现 3D图片浏览器的功能,如下: 2. 下面是详细的实现过程如下: (1)这里我是测试性代码,我的图片是自己添加到res/drawable/目录下的,如下: 但是开发中不 ...

  2. 一款基于 Android 开发的离线版的 MM 图片浏览 App

    一款离线版的 MM 图片浏览 App,有点类似掌上百度的图片专栏应用.图片采用瀑布流展示方式,点击图片集,支持左右手势滑动切换图片:支持放大缩小功能. 实现功能:1)图片完全离线,不耗个人 GPRS ...

  3. Android 大图片预览ViewPager

    项目gitHub地址:  https://github.com/bm-x/PhotoView 个人项目gitHub地址:  https://github.com/anan03/ananwork/tre ...

  4. 第17讲- UI常用组件之ImageView图片浏览

    第17讲 UI常用组件之ImageView图片浏览 二.图片浏览ImageView ImageView就是一个用来显示图片的视图: ImageView常见属性 常见属性 对应方法 说明 android ...

  5. Android压缩图片到100K以下并保持不失真的高效方法

    前言:目前一般手机的相机都能达到800万像素,像我的Galaxy Nexus才500万像素,拍摄的照片也有1.5M左右.这么大的照片上传到服务器,不仅浪费流量,同时还浪费时间. 在开发Android企 ...

  6. 仿优酷Android客户端图片左右滑动(自动滑动)

    最终效果: 页面布局main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayou ...

  7. 图片浏览(CATransition)转场动画

    Main.storyboard ViewController.m // //  ViewController.m //  8A04.图片浏览(转场动画) // //  Created by huan ...

  8. 用ticons指令结合ImageMagickDisplay工具批量生成Android适应图片

    用ticons指令结合ImageMagickDisplay工具批量生成Android适应图片 ticons的用法可以百度 这里记录下具体的编译方法 在安装了ticons和ImageMagickDisp ...

  9. Android 实现图片画画板

    本文主要讲述了Android 实现图片画画板 设计项目布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk ...

随机推荐

  1. @Autowired 和 @Resource

    转自:Spring中@Autowired注解.@Resource注解的区别 Spring不但支持自己定义的@Autowired注解,还支持几个由JSR-250规范定义的注解,它们分别是@Resourc ...

  2. js第一天 inner html value

    <html> <head> <meta charset="utf-8" /> <title></title> <s ...

  3. SSH-KeyGen 的用法

    假设 A 为客户机器,B为目标机: 要达到的目的:A机器ssh登录B机器无需输入密码:加密方式选 rsa|dsa均可以,默认dsa 做法:1.登录A机器 2.ssh-keygen -t [rsa|ds ...

  4. flash检测网络是否通畅

    air: 要在 Adobe ® Flash ® Professional(CS4 或更高版本)中使用 air.net 包: 选择“文件”>“发布设置”命令. 在 Flash 面板中,单击 Act ...

  5. Ansible3:ansible.cfg配置说明【转】

    Ansible默认安装好后有一个配置文件/etc/ansible/ansible.cfg,该配置文件中定义了ansible的主机的默认配置部分,如默认是否需要输入密码.是否开启sudo认证.actio ...

  6. 打不开BT,一直重复的关闭开启。

    /bt-btif (25335): ...preload_wait_timeout (retried:0/max-retry:1)...D/bt_userial(25335): RX terminat ...

  7. oracle数据库的数据类型

    一.字符类型 (1)固定长度的字符串 CHAR(字节长度是1~2000之间) CHAR(8)可以存储4个双字节的字符,8个单字节的字符,不足8字节剩余的部分用空格占据 (2)可变长度字符串 VARCH ...

  8. load

    http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages http://blog.scoutapp.com/ar ...

  9. Sublime console installation instructions install Package Control

    instructions: import urllib2,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1 ...

  10. RING0,RING1,RING2,RING3

    Intel的CPU将特权级别分为4个级别:RING0,RING1,RING2,RING3.Windows只使用其中的两个级别RING0和RING3,RING0只给操作系统用,RING3谁都能用.如果普 ...