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. 动态图表交互揭秘:制作选择器的奥秘
  2. 探索另类圆环图的做法
  3. 图表操作的几个技巧
  4. 一图看懂《对比Excel,轻松学习Python数据
  5. 计算1-1/2+1/3-1/4.......-1/100的值
  6. 利用Excel学习Python:准备篇
  7. 动态图表揭秘:“动”的关键——取数
  8. 利用Excel学习Python:变量
  9. 如何制作高大上的图表
  10. 从Excel的数据类型说Python