android中点击缩略图查看大图的方法一般有两种,一种是想新浪微博list页面那样,弹出一个窗口显示大图(原activity为背景)。另一种就是直接打开一个新的activity显示大图。

1、第一种方法我们可以使用自定义的AlertDialog来实现,代码如下:
ImageView image=(ImageView)findViewById(R.id.small_image);
image.setOnClickListener(new OnClickListener() { // 点击放大
public void onClick(View paramView) {
LayoutInflater inflater = LayoutInflater.from(context);
View imgEntryView = inflater.inflate(R.layout.dialog_photo_entry, null); // 加载自定义的布局文件
final AlertDialog dialog = new AlertDialog.Builder(context).create();
ImageView img = (ImageView)imgEntryView.findViewById(R.id.large_image);
imageDownloader.download("图片地址",img); // 这个是加载网络图片的,可以是自己的图片设置方法
dialog.setView(imgEntryView); // 自定义dialog
dialog.show();
// 点击布局文件(也可以理解为点击大图)后关闭dialog,这里的dialog不需要按钮
imgEntryView.setOnClickListener(new OnClickListener() {
public void onClick(View paramView) {
dialog.cancel();
}
});
}
});
对应的布局文件dialog_photo_entry内容为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" 
  xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView android:layout_height="wrap_content" android:id="@+id/large_image "
android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true">
</ImageView>
</RelativeLayout>
 
2、另外一种打开一个新的activity的方法相对简单点,大图activity代码如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_photo_entry);
activity = this;
Bundle bundle = this.getIntent().getExtras();
if(bundle!=null){
picName = bundle.getString("picName"); //图片名
}
ImageView img = (ImageView)this.findViewById(R.id.large_image );
imageDownloader.download( picName,img);
Toast toast = Toast.makeText(this, "点击图片即可返回",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
img.setOnClickListener(new View.OnClickListener() { // 点击返回
public void onClick(View paramView) {
activity.finish();
}
});
}
对应的布局文件dialog_photo_entry内容为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" 
   android:id="@+id/entry_pic" android:layout_margin="0dip" android:padding="0dip">
   <ImageView android:layout_height="wrap_content" android:id="@+id/large_image" 
       android:layout_marginTop="0dip" android:paddingTop="0dip"    
        android:adjustViewBounds="true"
android:layout_width="fill_parent">
</ImageView>
</ScrollView>
</LinearLayout>

android开发:点击缩略图查看大图的更多相关文章

  1. jquery层居中,点击小图查看大图,弹出层居中代码,顶部层固定不动,滚动条滚动情况

    jquery层居中,点击小图查看大图,弹出层居中代码 http://www.cnblogs.com/simpledev/p/3566280.html 见第一版,发现一个情况,如果页面内容多出一屏的情况 ...

  2. 点击图片查看大图(纯js)

    $(function(){ $(".pimg").click(function(){ var _this = $(this);//将当前的pimg元素作为_this传入函数 img ...

  3. [原创]WKWebview点击图片查看大图

    大家都知道,WKWebview是没有查看大图的属性或者方法的,所以只能通过js与之交互来实现这一功能,原理:通过js获取页面的图片,把它存放到数组,给图片添加点击事件,通过index显示大图就行了 其 ...

  4. WKWebview点击图片查看大图

    大家都知道,WKWebview是没有查看大图的属性或者方法的,所以只能通过js与之交互来实现这一功能,原理:通过js获取页面的图片,把它存放到数组,给图片添加点击事件,通过index显示大图就行了 其 ...

  5. jQuery点击缩略图切换大图代码

    很多网站上都会有点击缩略图切换成大图的效果,下面来分享一下它的源码 还是先来看效果截图 运行文件 然后点击下一张 下面分享源代码 html文件 <!DOCTYPE html PUBLIC &qu ...

  6. 点击小图查看大图jQuery插件FancyBox魔幻灯箱

    今日发现一个不错的JQuery插件FancyBox,也许早就有这个插件了,但是没名字,我就暂且叫他魔幻灯箱吧,采用Mac系统的样式.网传主要有以下功能:■弹出的窗口有很漂亮的阴影效果.■关联的对象(就 ...

  7. iOS点击cell查看大图,点击大图还原小图-b

    一.项目需求 用collectionView展示很多照片,点击某个照片,用全屏scrollView无限循环的方式查看图片.点击放大的图片,图片缩小到原先的尺寸. 如图gif1.gif所示,点击中间的图 ...

  8. JavaScript网站设计实践(五)编写photos.html页面,实现点击缩略图显示大图的效果

    一.photos.html页面,点击每一张缩略图,就在占位符的位置那里,显示对应的大图. 看到的页面效果是这样的: 1.实现思路 这个功能在之前的JavaScript美术馆那里已经实现了. 首先在页面 ...

  9. jQuery插件——imgbox(点击图片查看大图)

    需要的资源: 需要对应的js代码和css样式,大家可以通过www.htmldrive.net平台下载,也可以在我文章的底部下载.对应的资源如下,将资源引入页面(别忘了JQuery): 注意:jQuer ...

随机推荐

  1. Delphi XML-RPC 中文乱码解决方法

    http://download.csdn.net/user/csm2432/uploads/2

  2. git从指定的commit创建分支

    How do I create a new git branch from an old commit? git checkout -b justin a9c146a09505837ec03b Thi ...

  3. C# WinForm捕获未处理的异常

    using System; using System.Collections.Generic; using System.Windows.Forms; using System.IO; namespa ...

  4. WordPress Complete Gallery Manager插件‘upload-images.php’任意文件上传漏洞

    漏洞名称: WordPress Complete Gallery Manager插件‘upload-images.php’任意文件上传漏洞 CNNVD编号: CNNVD-201309-377 发布时间 ...

  5. 【转】Notepad++插件NppProject发布

    原文网址:http://darkbull.net/article/NppProject/ 如果notepad++安装在 系统盘/program files/ 目录下,可能会提示错误.将npp移到其他目 ...

  6. 数据表列名与数据库关键字冲突,在Hibernate下的解决办法

    设计了一个数据库,某一个列名字是key,这与mysql数据库关键字冲突了,Hibernate下save总是报错. 在mysql命令中,解决办法很简单,只需要将关键字key用引号括起来就好了. 在Hib ...

  7. HTML快速入门5——不规则表格、表格背景、边框颜色

    转自:http://blog.csdn.net/ysuncn/article/details/2214153 不规则表格 例子: <table border=1><tr>< ...

  8. Windows Phone SDK 8.0 安装系统要求

    Windows Phone SDK 8.0 是一个功能齐全的开发环境,可用于构建 Windows Phone 8.0 和 Windows Phone 7.5 的应用和游戏. Windows Phone ...

  9. WebSocket学习笔记IE,IOS,Android等设备的兼容性问

    WebSocket学习笔记IE,IOS,Android等设备的兼容性问 一.背景 公司最近准备将一套产品放到Andriod和IOS上面去,为了统一应用的开发方式,决定用各平台APP嵌套一个HTML5浏 ...

  10. poj 1556 The Doors(线段相交,最短路)

      The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7430   Accepted: 2915 Descr ...