【Android实战】Gallary+ImageSwicther图片查看器
仿照如今各大新闻站点图片新闻的浏览模式,上面展示详细图片(ImageSwitch),以下是能够滑动的小图片(Gallery)。
当中须要注意的是ImageSwitch须要定义一个工厂返回的组件,而且能够设置动画效果。
Gallery用适配器载入布局。其Gallery可设置。两个图片的间隔距离。
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ImageSwitcher
android:id="@+id/switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1" >
</ImageSwitcher> <Gallery
android:id="@+id/gallary"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:layout_weight="3"
android:spacing="20dp" /> </LinearLayout>
java类:
package com.gallaryandswitch; import android.app.Activity;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils; import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.ViewSwitcher.ViewFactory; import com.example.wangyitest.R; public class MainAct extends Activity {
ImageSwitcher imageSwitcher;
Gallery gallery;
int[] pics = { R.drawable.f1, R.drawable.f2, R.drawable.f3, R.drawable.f4,
R.drawable.f5, R.drawable.f6, R.drawable.f7, R.drawable.flower }; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.galleryswitch);
imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
gallery = (Gallery) findViewById(R.id.gallary);
imageSwitcher.setFactory(new ViewFactory() { @Override
public View makeView() {
// TODO Auto-generated method stub
ImageView imageView = new ImageView(getApplicationContext());
imageView.setScaleType(ScaleType.FIT_CENTER);
imageView.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.FILL_PARENT));
imageView.setBackgroundColor(getResources().getColor(
R.color.bg3));
return imageView;
}
}); imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(
getApplicationContext(), android.R.anim.fade_in));
imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(
getApplicationContext(), android.R.anim.fade_out));
gallery.setAdapter(new MyAdapter()); // gallery.setOnItemClickListener(new AdapterView.OnItemClickListener()
// {
//
// @Override
// public void onItemClick(AdapterView<? > parent, View view,
// int position, long id) {
// // TODO Auto-generated method stub
// imageSwitcher.setImageResource(pics[position]);
// }
// });
gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
imageSwitcher.setImageResource(pics[position]);
} @Override
public void onNothingSelected(AdapterView<? > parent) {
// TODO Auto-generated method stub }
}); } class MyAdapter extends BaseAdapter { @Override
public int getCount() {
// TODO Auto-generated method stub
return pics.length;
} @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
} @Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView imageView = new ImageView(getApplicationContext());
imageView.setScaleType(ScaleType.FIT_CENTER); imageView.setLayoutParams(new Gallery.LayoutParams(400,
Gallery.LayoutParams.WRAP_CONTENT)); imageView.setImageBitmap(BitmapFactory.decodeResource(
getResources(), pics[position]));
imageView.setBackgroundColor(getResources().getColor(R.color.bg2));
return imageView; }
} }
【Android实战】Gallary+ImageSwicther图片查看器的更多相关文章
- Android 调整透明度的图片查看器
本文以实例讲解了基于Android的可以调整透明度的图片查看器实现方法,具体如下: main.xml部分代码如下: <?xml version="1.0" encoding ...
- Android中的图片查看器
本案例,使用Eclipse来开发Android2.1版本号的图片查看器. 1)首先,打开Eclipse.新建一个Android2.1版本号的项目ShowTu,打开res/values中文件夹下的str ...
- Bitmap图片查看器
在Android 应用中使用assets目录下存放的资源文件,assets目录下存放的资源代表应用无法直接访问的原生资源,应用程序通过AssetManager以二 进制流的形式来读取资源.此应用是查看 ...
- wpf 仿QQ图片查看器
参考博客 WPF下的仿QQ图片查看器 wpf图片查看器,支持鼠标滚动缩放拖拽 实现效果 主要参考的WPF下的仿QQ图片查看器,原博主只给出了部分代码. 没有完成的部分 1.右下角缩略图是原图不是缩略图 ...
- 发布两款JQ小插件(图片查看器 + 分类选择器),开源
图片查看器,github地址:https://github.com/VaJoy/imgViewer 效果如下: 这款当初大概写了2小时,有点匆忙地赶出来的,使用的接口很简单: $.bindViewer ...
- wpf图片查看器,支持鼠标滚动缩放拖拽
最近项目需要,要用到一个图片查看器,类似于windows自带的图片查看器那样,鼠标滚动可以缩放,可以拖拽图片,于是就写了这个简单的图片查看器. 前台代码: <Window x:Class=&qu ...
- 用JQ仿造礼德财富网的图片查看器
现在就职于一家P2P平台,自然也会关注同行其它网站的前端技术,今天要仿造的是礼德内页的一个图片查看器效果.不过说白了,无论人人贷也好礼德财富也好,很多地方的前端都做的不尽如人意,比如忽略细节.缺乏交互 ...
- 基于jQuery的一个简单的图片查看器
项目中自己diy了一个图片查看器.因为初始代码不是自己的,只是在上面改了一下也没有弄的很漂亮.等以后有时间了在重写一下样式和封装,作为备用的只是积累吧.如果有童鞋有用到,完全可以在此基础上改,比较容易 ...
- Objective-C ,ios,iphone开发基础:快速实现一个简单的图片查看器
新建一个single view 工程: 关闭ARC , 在.xib视图文件上拖放一个UIImageView 两个UIButton ,一个UISlider ,布局如图. 并为他们连线, UIImage ...
随机推荐
- a:active在ios上无效解决方法
原因: By default, Safari Mobile does not use the :active state unless there is a touchstart event hand ...
- artTemplate模板引擎的不同使用方式
arttemplate提供了两种不同的使用方式 一种是将模板写在页面内 <script id="test" type="text/html"> &l ...
- idea如何设置类头注释和方法注释(带注释模板)
1.idea类注释 打开:file->setting->Editor->Filr and Code Templates->Includes->File Header 类注 ...
- ckeditor与ckfinder的使用方法 .NET (转载)
原文发布时间为:2009-11-25 -- 来源于本人的百度文章 [由搬家工具导入] ckeditor与ckfinder的使用方法 .NET (转载) ckeditor 3.0.1学习笔记 一.ck ...
- 关于platform_device和platform_driver的匹配【转】
转自:http://blog.csdn.net/dfysy/article/details/5959451 版权声明:本文为博主原创文章,未经博主允许不得转载. 说句老实话,我不太喜欢现在Linux ...
- centos7下配置时间同步服务器
同网段20几台服务器: 其中有一组mysql 集群中 互为主从 选一台mysql master 作为时间同步的服务器,这样做的好处以便于这台down了 另一个与他互为主从的master 继续提供时间同 ...
- Vscode 小白使用介绍
前言 现在使用Vscode编码的人越来越多,凭借着免费,开源,轻量,跨平台的特点收货了一大批忠实粉丝 最近因项目需要开始使用Vscode,但不知为何,感觉有点力不从心,不知道该怎么用 首先想到去官 ...
- python 设计模式之命令模式
命令模式介绍: 在面向对象编程中,命令模式是概括所有方法信息的设计模式. 此模式对象包涵方法名,及其相关参数值. 命令模式是一个分类的观察者设计模式,在命令模式下,对象被概括为一个命令表单,此表单包涵 ...
- luogu P3147 [USACO16OPEN]262144
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...
- luogu P2434 [SDOI2005]区间
题目描述 现给定n个闭区间[ai, bi],1<=i<=n.这些区间的并可以表示为一些不相交的闭区间的并.你的任务就是在这些表示方式中找出包含最少区间的方案.你的输出应该按照区间的升序排列 ...