android-gallery游览图片点击图片放大

简介:
  1. package com.hua.com;     
  2. import android.app.Activity;     
  3. import android.content.Context;     
  4. import android.os.Bundle;     
  5. import android.view.View;     
  6. import android.view.ViewGroup;     
  7. import android.view.animation.Animation;     
  8. import android.view.animation.AnimationSet;     
  9. import android.view.animation.ScaleAnimation;     
  10. import android.widget.AdapterView;     
  11. import android.widget.AdapterView.OnItemClickListener;     
  12. import android.widget.AdapterView.OnItemSelectedListener;     
  13. import android.widget.BaseAdapter;     
  14. import android.widget.Gallery;     
  15. import android.widget.ImageView;     
  16. public class TestGalleryActivity extends Activity {     
  17.     private Gallery gallery;     
  18.     private AnimationSet manimationSet;     
  19.     private int[] imgs;     
  20.     @Override     
  21.     public void onCreate(Bundle savedInstanceState) {     
  22.         super.onCreate(savedInstanceState);     
  23.         setContentView(R.layout.main);     
  24.         init();     
  25.     }     
  26.     private void init(){     
  27.         imgs=new int[]{R.drawable.a,R.drawable.c,R.drawable.d,R.drawable.y,R.drawable.f};     
  28.         gallery = (Gallery)findViewById(R.id.gy_main);     
  29.         ImageAdapter imgAdapter = new ImageAdapter(this,imgs);     
  30.         gallery.setAdapter(imgAdapter);     
  31.         gallery.setSelection(imgs.length/2);     
  32.         gallery.setOnItemClickListener(listener);     
  33.              
  34.     }     
  35.     private OnItemClickListener listener = new  OnItemClickListener(){     
  36.         @Override     
  37.         public void onItemClick(AdapterView<?> parent, View view, int position,     
  38.                 long id) {     
  39.             if(position!=0&&position!=4){     
  40.                 AnimationSet animationSet = new AnimationSet(true);     
  41.                 if(manimationSet!=null&&manimationSet!=animationSet){     
  42.                      ScaleAnimation scaleAnimation = new ScaleAnimation(2,0.5f,2,0.5f,     
  43.                              Animation.RELATIVE_TO_SELF,0.5f,   //使用动画播放图片     
  44.                               Animation.RELATIVE_TO_SELF,0.5f);     
  45.                             scaleAnimation.setDuration(1000);     
  46.                             manimationSet.addAnimation(scaleAnimation);     
  47.                             manimationSet.setFillAfter(true); //让其保持动画结束时的状态。     
  48.                            view.startAnimation(manimationSet);     
  49.                 }     
  50.                      ScaleAnimation scaleAnimation = new ScaleAnimation(1,2f,1,2f,     
  51.                              Animation.RELATIVE_TO_SELF,0.5f,      
  52.                              Animation.RELATIVE_TO_SELF,0.5f);     
  53.                            scaleAnimation.setDuration(1000);     
  54.                            animationSet.addAnimation(scaleAnimation);     
  55.                            animationSet.setFillAfter(true);      
  56.                            view.startAnimation(animationSet);     
  57.                            manimationSet = animationSet;     
  58.                      
  59.                 }else{     
  60.                     if(null!=manimationSet)manimationSet.setFillAfter(false);     
  61.                 }     
  62.         }     
  63.     };     
  64.     class ImageAdapter extends BaseAdapter{     
  65.         private Context ct;     
  66.         private int[] data;     
  67.         public ImageAdapter(Context ct,int[] data){     
  68.             this.ct=ct;     
  69.             this.data=data;     
  70.         }     
  71.         @Override     
  72.         public int getCount() {     
  73.             return data.length;     
  74.         }     
  75.         @Override     
  76.         public Object getItem(int position) {     
  77.             return data[position];     
  78.         }     
  79.         @Override     
  80.         public long getItemId(int position) {     
  81.             return position;     
  82.         }     
  83.         @Override     
  84.         public View getView(int position, View convertView, ViewGroup parent) {     
  85.             View view = null;     
  86.             if(convertView==null){     
  87.                 ImageView img = new ImageView(ct);     
  88.                 img.setImageResource(data[position]);     
  89.                 view=img;     
  90.             }else{     
  91.                 view=convertView;     
  92.             }     
  93.             return view;     
  94.         }     
  95.     }     
  96. }     


  1. view plainprint?   
  2. <?xml version="1.0" encoding="utf-8"?>     
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     
  4.     android:orientation="vertical"     
  5.     android:layout_width="fill_parent"     
  6.     android:layout_height="fill_parent"     
  7.     >     
  8. <TextView       
  9.     android:layout_width="fill_parent"      
  10.     android:layout_height="wrap_content"      
  11.     android:text="@string/hello"     
  12.     />     
  13.     <Gallery     
  14.     android:id="@+id/gy_main"     
  15.     android:layout_width="fill_parent"      
  16.     android:layout_height="fill_parent"      
  17.     android:layout_gravity="center_horizontal"     
  18.     android:spacing="10dip"     
  19.     android:layout_centerHorizontal="true"      
  20.          
  21.          
  22.     />     
  23. </LinearLayout>    

相关文章
|
11月前
|
XML Java Android开发
Android Studio App开发之对图片进行简单加工(包括放缩,旋转等等 附源码)
Android Studio App开发之对图片进行简单加工(包括放缩,旋转等等 附源码)
262 0
|
11月前
|
Android开发
Android通过手势(多点)缩放和拖拽图片
Android通过手势(多点)缩放和拖拽图片
104 4
|
11月前
|
Java Android开发
android 下载图片的问题
android 下载图片的问题
83 3
|
7月前
|
存储 缓存 编解码
Android经典面试题之图片Bitmap怎么做优化
本文介绍了图片相关的内存优化方法,包括分辨率适配、图片压缩与缓存。文中详细讲解了如何根据不同分辨率放置图片资源,避免图片拉伸变形;并通过示例代码展示了使用`BitmapFactory.Options`进行图片压缩的具体步骤。此外,还介绍了Glide等第三方库如何利用LRU算法实现高效图片缓存。
117 20
Android经典面试题之图片Bitmap怎么做优化
|
8月前
|
数据处理 开发工具 数据安全/隐私保护
Android平台RTMP推送|轻量级RTSP服务|GB28181接入之文字、png图片水印的精进之路
本文探讨了Android平台上推流模块中添加文字与PNG水印的技术演进。自2015年起,为了满足应急指挥及安防领域的需求,逐步发展出三代水印技术:第一代为静态文字与图像水印;第二代实现了动态更新水印内容的能力,例如实时位置与时间信息;至第三代,则优化了数据传输效率,直接使用Bitmap对象传递水印数据至JNI层,减少了内存拷贝次数。这些迭代不仅提升了用户体验和技术效率,也体现了开发者追求极致与不断创新的精神。
|
8月前
|
自然语言处理 定位技术 API
Android经典实战之如何获取图片的经纬度以及如何根据经纬度获取对应的地点名称
本文介绍如何在Android中从图片提取地理位置信息并转换为地址。首先利用`ExifInterface`获取图片内的经纬度,然后通过`Geocoder`将经纬度转为地址。注意操作需在子线程进行且考虑多语言支持。
450 4
|
8月前
|
XML 前端开发 Android开发
Android经典实战之Kotlin中实现圆角图片和圆形图片
本文介绍两种实现圆角图像视图的方法。第一种是通过自定义Kotlin `AppCompatImageView`,重写`onDraw`方法使用`Canvas`和`Path`进行圆角剪裁。第二种利用Android Material库中的`ShapeableImageView`,简单配置即可实现圆角效果。两种方法均易于实现且提供动态调整圆角半径的功能。
152 0
|
11月前
|
XML JSON Java
Android App开发即时通信中通过SocketIO在客户端与服务端间传输文本和图片的讲解及实战(超详细 附源码)
Android App开发即时通信中通过SocketIO在客户端与服务端间传输文本和图片的讲解及实战(超详细 附源码)
601 0
|
10月前
|
Java Android开发
18. 【Android教程】图片控件 ImageView
18. 【Android教程】图片控件 ImageView
166 4
|
10月前
|
JSON 编解码 Apache
Android中使用HttpURLConnection实现GET POST JSON数据与下载图片
Android中使用HttpURLConnection实现GET POST JSON数据与下载图片
113 1

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等