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配合使用,实现图片预览的更多相关文章

  1. 自定义type为file型input控件+该控件具有本地图片预览功能

    最近的一个项目需求是写一个type为filex型的input控件,这个控件: 第一,要自定义样式: 第二,要能直接在本地预览上传的图片: 第三,要能检测图片的尺寸是否符合要求. 故综合网上的资源写了下 ...

  2. dropzonejs中文翻译手册 DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.

    http://wxb.github.io/dropzonejs.com.zh-CN/dropzonezh-CN/ 由于项目需要,完成一个web的图片拖拽上传,也就顺便学习和了解了一下前端的比较新的技术 ...

  3. 实现QQ空间图片预览效果

    今天项目遇到需求 要求 实现图片预览效果 .  类似于扣扣空间那种,本人也到网上找过 代码量太大了   ,类多到处是注释看的有点恶心 .然后自己写了一个图片预览的效果,其实很简单的 . 首先我们来分析 ...

  4. angular中封装fancyBox(图片预览)

    首先在官网下载最新版的fancyBox(一定要去最新网站,以前依赖的jquery版本偏低),附上链接:http://fancyapps.com/fancybox/3/ 然后在项目中引用jquery,然 ...

  5. input[type='file']样式美化及实现图片预览

    前言 上传图片是常见的需求,多使用input标签.本文主要介绍 input标签的样式美化 和 实现图片预览. 用到的知识点有: 1.input标签的使用 2.filelist对象 和 file对象 3 ...

  6. 在 vue 中使用 vieiwer 图片预览插件

    https://blog.csdn.net/WestLonly/article/details/79801800?utm_source=blogxgwz0 首先,感谢原作者 官网链接 github地址 ...

  7. js实现移动端图片预览:手势缩放, 手势拖动,双击放大...

    .katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...

  8. DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.

    DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库. 它是轻量级的,不依赖任何其他类库(如JQuery)并且高度可定制. 试试看! 将文件拖至此处或点击上传.(这仅仅是 dropzo ...

  9. Ionic实战三:Ionic 图片预览可放大缩小左右滑动demo-iClub图片预览

    这个demo的主要功能有两个,一个是首页的导航向上拉动会浮动在最上面的效果,另一个就是我们平时非常实用的功能,就是图片预览功能 点击可以放大图片,并且可以左右滑动,还可以双击放大缩小图片以及双手指控制 ...

随机推荐

  1. CF 554A 字符串水题

    给出一个字符串,问再加入一个字母,最多能形成多少种字符串 inputaoutput51inputhioutput76 # include <iostream> # include < ...

  2. maven centos7 环境变量

    tar -xvf apache-maven-3.3.9-bin.tar.gz mv apache-maven-3.3.9 /usr/local/apache-maven 文件存放好之后,设置环境变量, ...

  3. ThinkPHP 获取指定日期后第N个工作日具体日期

    思路: 1.获取到查询年份内所有工作日数据数组2.获取到查询开始日期在工作日的索引3.计算需查询日期索引4.获得查询日期 /*创建日期类型记录表格*/ CREATE TABLE `tb_workday ...

  4. 决策树ID3算法--python实现

    参考: 统计学习方法>第五章决策树]   http://pan.baidu.com/s/1hrTscza 决策树的python实现     有完整程序     决策树(ID3.C4.5.CART ...

  5. JAVA JMX协议监控

    JMX协议监控,可通过JMX协议远程监控,实时监控线上jvm情况,并通过平台管理界面进行 展示,可以通过监控实时获得线上服务器运行情况. 可以监控内存.实时线程.共享内存等各种信息. 获取实时线程信息 ...

  6. hiho1270 建造基地([Offer收割]编程练习赛1)

    题目意思很简单, 一道类似于背包的问题,问恰好超过背包容量的最小取值.并且需要计算n次,每计算一次都要将所有的物品的价值w[i] /= t,最后输出背包n次的总使用容量. 如果无法实现输出”No An ...

  7. Codeforces Round #369 (Div. 2) D. Directed Roads 数学

    D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and ...

  8. Mac下配置Apache服务器

    有的时候,我们需要在内网工作组中分享一些文件或是后台接口没有及时给出,你又想要模拟真实数据,直接在项目里创建plist也可以做到这种需求,但难免让工程变得冗余且看起来比较Low.这个时候就看出配置本地 ...

  9. MyBatis中使用#{}和${}的区别

    select * from table_name where id=#{id}; select * from table_name where id=${id}; 区别: 在动态SQL解析阶段,#{} ...

  10. OpenVPN使用easy-rsa3吊销证书

    cd /etc/easy-rsa ./easyrsa revoke targetkey(证书名) ./easyrsa gen-crl 其中gen-crl会生成一份吊销证书的名单,放在pki/crl.p ...