Gallery和自定义Adapter配合使用,实现图片预览
Gallery是一个可以拖动的列表,正中对应的是选中的东西.他和spinner有共同的父类:AbsSpinner
属性:
android:animationDuration="1000" 图片切换动画持续时间
android:spacing="8dp" 设置图片之间的间距
android:unselectedAlpha="0.6" 设置没有选择的图片的透明度
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kale.gallery.MainActivity"
android:orientation="vertical"> <!--
android:animationDuration="1000" 图片切换动画持续时间
android:spacing="8dp" 设置图片之间的间距
android:unselectedAlpha="0.6" 设置没有选择的图片的透明度
-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用ImageView作预览图"
android:textAppearance="?android:attr/textAppearanceMedium" /> <ImageView
android:id="@+id/imageView_id"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="下方是gallery"
android:textAppearance="?android:attr/textAppearanceMedium" /> <Gallery
android:id="@+id/gallery_id"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="80dp"
android:animationDuration="1000"
android:spacing="8dp"
android:unselectedAlpha="0.3"/> </LinearLayout>
MainActivity.java
package com.kale.gallery; import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView; @SuppressWarnings("deprecation")
public class MainActivity extends Activity { ImageView iV;
Gallery gallery; int[] imageIds = new int [] {
R.drawable.appstore,
R.drawable.cydia,
R.drawable.itunes,
R.drawable.mail,
R.drawable.safair
}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); viewInit();
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemSelectedListener(new OnItemSelectedListener() { @Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO 自动生成的方法存根
iV.setImageResource(imageIds[arg2]); } @Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO 自动生成的方法存根 }
});
} public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context context) {
mContext = context;
} public int getCount() {
return imageIds.length;
} public Object getItem(int position) {
return position;
} public long getItemId(int position) {
return position;
} public View getView(int position, View convertView, ViewGroup parent) {
ImageView image = new ImageView(mContext);
image.setImageResource(imageIds[position]);
//设置缩放类型
image.setScaleType(ImageView.ScaleType.FIT_XY);
image.setAdjustViewBounds(true);
//设置布局参数
image.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
return image;
}
} private void viewInit() {
// TODO 自动生成的方法存根
gallery = (Gallery) findViewById(R.id.gallery_id);
iV = (ImageView)findViewById(R.id.imageView_id);
} }
Gallery和自定义Adapter配合使用,实现图片预览的更多相关文章
- 自定义type为file型input控件+该控件具有本地图片预览功能
最近的一个项目需求是写一个type为filex型的input控件,这个控件: 第一,要自定义样式: 第二,要能直接在本地预览上传的图片: 第三,要能检测图片的尺寸是否符合要求. 故综合网上的资源写了下 ...
- dropzonejs中文翻译手册 DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.
http://wxb.github.io/dropzonejs.com.zh-CN/dropzonezh-CN/ 由于项目需要,完成一个web的图片拖拽上传,也就顺便学习和了解了一下前端的比较新的技术 ...
- 实现QQ空间图片预览效果
今天项目遇到需求 要求 实现图片预览效果 . 类似于扣扣空间那种,本人也到网上找过 代码量太大了 ,类多到处是注释看的有点恶心 .然后自己写了一个图片预览的效果,其实很简单的 . 首先我们来分析 ...
- angular中封装fancyBox(图片预览)
首先在官网下载最新版的fancyBox(一定要去最新网站,以前依赖的jquery版本偏低),附上链接:http://fancyapps.com/fancybox/3/ 然后在项目中引用jquery,然 ...
- input[type='file']样式美化及实现图片预览
前言 上传图片是常见的需求,多使用input标签.本文主要介绍 input标签的样式美化 和 实现图片预览. 用到的知识点有: 1.input标签的使用 2.filelist对象 和 file对象 3 ...
- 在 vue 中使用 vieiwer 图片预览插件
https://blog.csdn.net/WestLonly/article/details/79801800?utm_source=blogxgwz0 首先,感谢原作者 官网链接 github地址 ...
- js实现移动端图片预览:手势缩放, 手势拖动,双击放大...
.katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...
- DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.
DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库. 它是轻量级的,不依赖任何其他类库(如JQuery)并且高度可定制. 试试看! 将文件拖至此处或点击上传.(这仅仅是 dropzo ...
- Ionic实战三:Ionic 图片预览可放大缩小左右滑动demo-iClub图片预览
这个demo的主要功能有两个,一个是首页的导航向上拉动会浮动在最上面的效果,另一个就是我们平时非常实用的功能,就是图片预览功能 点击可以放大图片,并且可以左右滑动,还可以双击放大缩小图片以及双手指控制 ...
随机推荐
- 001 SpringMVC的helloWorld程序
一:helloworld程序 1.结构目录 2.添加lib包 3.在web.xml中配置DispatchServlet 这个就是主servlet. <?xml version="1.0 ...
- chrome书签(收藏栏)的导入导出
- mysql 事务隔离级别 详解
问题 在工作中真实遇到的问题:用python连接mysql,查询数据,同时有别的代码在更新mysql中的数据,前者是一直是保持连接的数据库,每一分钟select一次,但第二次却查不到更新后的数据?wh ...
- Uncaught Error: Syntax error, unrecognized expression: [flag=]报错处理方法
今早运行项目的时候报这个错误: 百度翻译的解释是:未命名错误:语法错误,未识别表达式:[FLAG= ] 也就是书写规范问题. 可是我查了对应的js: 字符串拼接没什么问题,经常这样写. 这时看报错 ...
- [POI2013]Łuk triumfalny
[POI2013]Łuk triumfalny 题目大意: 一棵\(n(n\le3\times10^5)\)个结点的树,一开始\(1\)号结点为黑色.\(A\)与\(B\)进行游戏,每次\(B\)能选 ...
- KVM和QEMU简介
KVM/QEMU简介 KVM虚拟机是基于linux内核虚拟化,自linux2.6.20之后就集成在linux的各个主要发行版本中.它使用linux自身的调度器进行管理,所以相对于xen,其核心源码很少 ...
- 马士兵hadoop第四课:Yarn和Map/Reduce配置启动和原理讲解
马士兵hadoop第一课:虚拟机搭建和安装hadoop及启动 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作 马士兵hadoop第三课:java开发hdfs 马士兵hadoop第 ...
- logstash高速入口
原文地址:http://logstash.net/docs/1.4.2/tutorials/getting-started-with-logstash 英语水平有限,假设有错误请各位指正 简单介绍 L ...
- windows pm2 开机启动
npm install pm2-windows-startup -g; pm2-startup install; pm2 kill; pm2 start ecosystem.config.js --o ...
- 群晖NAS的Docker容器使用中国镜像加速
vi /var/packages/Docker/etc/dockerd.json 添加如下内容: { "registry-mirrors": ["https://regi ...