【Android】5.7 图片库(Galery)
分类:C#、Android、VS2015;
创建日期:2016-02-07
一、简介
图库(也叫画廊)是一个布局小部件,用于在可水平滚动的列表中显示每一副图片,当前所选的图片将置于视图的中心。
注意:Android已经弃用了这个小部件,弃用的原因是用Galery实现的效率比较低,官方的建议是改为用HorizontalScrollView来替代这个小部件。但是,目前手机上的图片浏览功能很多都是用Galery来实现的,如果你仍然喜欢这个小部件,也可以在高版本的项目中继续使用它。
二、示例8--Demo08Gallery
1、运行截图
在模拟器中用鼠标左右拖放图片观察效果。
2、添加Demo08Gallery.axml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical">
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
保存文件,然后单击解决方案资源管理器上方的【刷新】按钮。
3、添加Demo08Gallery.cs文件
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Views;
using Android.Widget;
using Java.Lang; namespace ch05demos.SrcActivity
{
[Activity(Label = "Demo08Gallery")]
public class Demo08Gallery : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.demo08_Gallery);
var g = FindViewById<Gallery>(Resource.Id.gallery);
g.Adapter = new ImageAdapter(this)
{
CurrentWidth = ,
CurrentHeight =
};
g.ItemClick += Gallery_ItemClick;
} private void Gallery_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
Toast.MakeText(this, e.Position.ToString(), ToastLength.Short).Show();
}
}
public class ImageAdapter : BaseAdapter
{
private Context context;
private int[] thumbIds = {
Resource.Drawable.sample_1,
Resource.Drawable.sample_2,
Resource.Drawable.sample_3,
Resource.Drawable.sample_4,
Resource.Drawable.sample_5,
Resource.Drawable.sample_6,
Resource.Drawable.sample_7
}; //默认值为500(这是C# 6.0新增的功能,仅VS2015可以这样用)
public int CurrentWidth { get; set; } = ;
public int CurrentHeight { get; set; } = ; public ImageAdapter(Context c)
{
context = c;
} public override int Count
{
get { return thumbIds.Length; }
} public override View GetView(int position, View convertView, ViewGroup parent)
{
ImageView i = new ImageView(context);
i.SetImageResource(thumbIds[position]);
i.LayoutParameters = new Gallery.LayoutParams(, );
i.SetScaleType(ImageView.ScaleType.FitXy);
return i;
} public override long GetItemId(int position)
{
return ;
} public override Java.Lang.Object GetItem(int position)
{
return null;
}
}
}
运行。
【Android】5.7 图片库(Galery)的更多相关文章
- Android之Fresco(facebook的强大Android图片加载的框架)
Fresco是Facebook最新推出的一款用于Android应用中展示图片的强大图片库,可以从网络.本地存储和本地资源中加载图片.其中的Drawees可以显示占位符,直到图片加载完成.而当图片从屏幕 ...
- Android图片下载以及缓存框架
实际开发中进行图片下载以及缓存的框架 介绍一下开发中常见图片加载框架的使用和对比一下优缺点. 1.Picasso 框架 在Android中开发,常需要从远程获取图片并显示在客户端,当然我们可以使用原生 ...
- Android 图片处理之 Fresco
一.关于 Fresco github: https://github.com/facebook/fresco API: http://www.fresco-cn.org/javadoc/referen ...
- 96、facebook Fresco框架库源使用基础
开源项目链接 facebook Fresco仓库:git clone https://github.com/facebook/fresco facebook Fresco主页:“>http:// ...
- Universal-Image-Loader,android-Volley,Picasso、Fresco和Glide图片缓存库的联系与区别
Universal-Image-Loader,android-Volley,Picasso.Fresco和Glide五大Android开源组件加载网络图片比较 在Android中的加载网络图片是一件十 ...
- 96、facebook Fresco框架库源使用(转载)
各个属性详情:http://blog.csdn.net/y1scp/article/details/49245535 开源项目链接 facebook Fresco仓库:git clone https: ...
- Fresco,Facbook强大的图片加载框架
项目git地址:https://github.com/facebook/fresco Fresco是 facebook推出的一款强大的图片加载的框架:主要有Image Pipeline和Drawees ...
- FaceBook开源库Fresco
讨论学习使用 关于 Fresco Fresco 是一个强大的图片载入组件. Fresco 中设计有一个叫做 image pipeline 的模块.它负责从网络.从本地文件系统.本地资源载入图片. 为了 ...
- Android 圆形图片库 CircleImageView
高仿微信朋友圈 10s 视频裁剪 引语 晚上好,我是猫咪,我的公众号「程序媛猫咪」会推荐 GitHub 上好玩的项目,挖掘开源的价值,欢迎关注我. <Android 图片裁剪库 uCrop> ...
随机推荐
- 微信小程序 - 各种示例
示例更新(后续持续更新): 最后一次更新:2018-11-7 小程序-地图显示(调用高德地图.腾讯App) - (2018-11-1) 小程序-上传图片(上传.预览.展示.删除) - (2018-11 ...
- more命令(转)
原文:http://www.cnblogs.com/peida/archive/2012/11/02/2750588.html more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示 ...
- 如何开启firebug显示注释?
如何开启firebug注释显示?
- 通过jaxws-ri创建webservice服务端和客户端
1. 获得开发包 当然是到 SUN 的开发网站下载 JAX-WS RI,或者下载我的网盘备份 ,下载下来的只是一个jar包,参考官网上的方法在命令行调用:java -jar JAXWS2.1.2-20 ...
- 【OpenERP】Report 生成
以模块oecnj_trainning为例,模块路径: ~/openerp/addons/oecn_training/ ,以下简写为 path/oecn/ Report生成方法:(手写) rml + r ...
- poj 2195 Going Home(最小费最大流)
poj 2195 Going Home Description On a grid map there are n little men and n houses. In each unit time ...
- 【BIEE】导出数据报错
使用BIEE导出数据的时候,发现个问题,导出过程中,报错如下: 问题解决: 找到文件opmn.xml,路径为:/Middleware/instances/instance1/config/OPMN/o ...
- oracl查询锁表语句
技能源于生活的不断实践,实践是对知识的不断扩展和总结.汇总.进而形成思想体系! --查询锁表语句 select sess.sid, sess.serial#, lo.oracle_username, ...
- PHP中的一些安全配置
PHP中的配置至关重要,包含php.ini的配置,还有系统权限的配置,一下是我总结的一些配置 一.PHP的模块 ./configure \ --with-libdir=lib64 \ --prefix ...
- SpringBoot自定义HttpMessageConverter
Spring就是一个大大的插线板,上面插着各种各样的Bean. SpringBoot大大简化了Spring的配置,将原来放在XML中的配置大量的在代码中使用注解实现.这么做有利有弊,总体上利大于弊. ...