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"?>     < ImageView android:layout_height="wrap_content" android:id="@+id/ large_image " android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true">
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"?> < ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"     android:id="@+id/entry_pic" android:layout_margin="0dip" android:padding="0dip">    large_image"         android:layout_marginTop="0dip" android:paddingTop="0dip"             android:adjustViewBounds="true" android:layout_width="fill_parent">

更多相关文章

  1. Android(安卓)高级编程--Fragment理解与使用
  2. color用法大全--Android布局背景颜色设置
  3. AndroidGUI27:findViewById返回null的解决办法
  4. 最全面的Android(安卓)Studio使用教程
  5. Android(安卓)弹出式布局之Dialog源码分析
  6. Material Design之TabLayout的用法(标题栏滑动+ViewPager)
  7. android 自定义Toast增加点击事件、Toast弹出隐藏动画、Toast宽
  8. 【Android】安卓布局文件中xmlns属性
  9. 关于android的开发环境

随机推荐

  1. MySql 存储引擎和索引相关知识总结
  2. mysql安装navicat之后,出现2059,Authenti
  3. MySQL 8.0.20 Window10免安装版配置及Nav
  4. 基于sqlalchemy对mysql实现增删改查操作
  5. MySQL数据库备份恢复实现代码
  6. MYSQL中binlog优化的一些思考汇总
  7. Mysql 查询数据库容量大小的方法步骤
  8. Linux下mysql异地自动备份的方法
  9. mysql 使用存储过程实现树节点的获取方法
  10. MySQL横纵表相互转化操作实现方法