【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 ...
随机推荐
- 数组去重js方式
var selectmap = new Array(); /(\x0f[^\x0f]+)\x0f[\s\S]*\1/.test("\x0f"+selectmap.join(&quo ...
- 如何在vue里实现同步阻塞请求,请求完成之前不加载页面或组件?
https://segmentfault.com/q/1010000013787292 答案: getUserInfo函数数据请求下来,设置开关flag=true,页面最外层box v-if=&quo ...
- MySQL常用查询方法
SELECT TIME(NOW()); -- 15:23:07 SELECT CURTIME(NOW());-- 15:23:07 SELECT ABS(-4); -- 4 SELECT 5 MOD ...
- MYSQL常用命令——【转】
MYSQL常用命令 1.导出整个数据库mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin ...
- 一些汇编中的 trick
1. PC 总是指向下一条将要被执行的指令,而不是指向正在被执行的指令,这是有道理的,因为执行指令不是一个 atom 过程,而是分成了好多步骤,在执行指令的过程中 cpu 完全有可能将下一条将要执行的 ...
- [LeetCode] Length of Last Word 字符串查找
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 关于mysql编码问题
1 查看MySQL编码 SHOW VARIABLES LIKE 'char%';
- CentOS下VNC使用
1. 介绍 本文主要介绍了VNC Server的配置和使用 2. 安装 CentOS中默认就有安装VNC,可以通过命令rpm查看 [Jerry@localhost ~]$ rpm -qa | grep ...
- [SaltStack] 基础介绍
今天有时间把以前研究过的saltstack梳理总结下 -:) salt是干什么的我就不多说了, 大家Google下资料很多的, 简单来说就是func+puppet: 配置文件管理 远程命令调用 Cro ...
- ubuntu 15.10 64bit 下 steam无法启动
首先查看steam日志,在/tmp/dumps/下,以“用户名_output.txt”命名. $ cat /tmp/dumps/liuxu_output.txt Running Steam on ub ...