【Android实战】Gallary+ImageSwicther图片查看器
来源:互联网 发布:显示器连接网络机顶盒 编辑:程序博客网 时间:2024/05/21 10:04
仿照现在各大新闻网站图片新闻的浏览模式,上面展示具体图片(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 };@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.galleryswitch);imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher);gallery = (Gallery) findViewById(R.id.gallary);imageSwitcher.setFactory(new ViewFactory() {@Overridepublic View makeView() {// TODO Auto-generated method stubImageView 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() {@Overridepublic void onItemSelected(AdapterView<?> parent, View view,int position, long id) {// TODO Auto-generated method stubimageSwitcher.setImageResource(pics[position]);}@Overridepublic void onNothingSelected(AdapterView<?> parent) {// TODO Auto-generated method stub}});}class MyAdapter extends BaseAdapter {@Overridepublic int getCount() {// TODO Auto-generated method stubreturn pics.length;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubImageView 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;}}}
0 0
- 【Android实战】Gallary+ImageSwicther图片查看器
- android开发之拖动图片(Gallary )
- android学习之路(三)高级组件之图片切换器<ImageSwicther/>以及final关键字的基本用法
- Android 画廊控件Gallary
- Gallary
- Android Gallary图片游览效果--透明的倒影,层叠的图片,渐变的颜色透明度
- Android Gallary图片游览效果--透明的倒影,层叠的图片,渐变的颜色透明度
- Android图片查看器
- Android 图片查看器
- Android图片查看器
- Android图片查看器
- html5带拖拽上传的图片gallary
- Android简易实战教程--第二十五话《网络图片查看器》
- Android简易实战教程--第二十六话《网络图片查看器在本地缓存》
- Android 网络图片查看器
- Android中的图片查看器
- Android网络图片查看器
- Android网络图片查看器
- 扑克牌上四个花色人物的故事,及其代表意义
- 简单计算器
- Android中遇到的需求与解决方案一
- Eclipse 工作空间项目过多的解决办法
- I006-黑马程序员_毕向东_Java基础视频教程第01天-06-Java环境搭建(环境变量临时配置方式)
- 【Android实战】Gallary+ImageSwicther图片查看器
- 基于角色的权限控制在Drupal7中的实现
- 安卓报错解决方案
- Java和Flex整合报错(一)
- 计算指定时间与当前的时间差 比如,3天前、10分钟前
- HDOJ1228 A+B
- js函数的length属性和call和apply函数详解
- 手工创建数据库
- Linux常用命令(七) - cp