结构:

Activity:

 <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:orientation="vertical"
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.example.top6_3.MainActivity" >
<Gallery
android:id="@+id/gly"
android:layout_height="60dp"
android:layout_width="fill_parent"
android:animationDuration=""
android:gravity="center_vertical"
android:spacing="20dp"
android:unselectedAlpha="0.5"
android:background="#55000000"
/>
<ImageSwitcher
android:paddingTop="10dp"
android:id="@+id/is"
android:layout_width="wrap_content"
android:layout_height="match_parent"></ImageSwitcher> </LinearLayout>

JAVA:

MainActivity类:
 package com.example.top6_3;

 import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Gallery.LayoutParams;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory; public class MainActivity extends Activity {
private Gallery gal;
private ImageView iv;
private ImageAdapter adapter;
private ImageSwitcher is;
private static final int[] imgslds={
R.drawable.bjl,
R.drawable.dfhgc,
R.drawable.fg,
R.drawable.gj
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
is=(ImageSwitcher) findViewById(R.id.is);
is.setFactory(new ViewFactory() { @Override
public View makeView() {
// TODO Auto-generated method stub
ImageView i=new ImageView(getApplicationContext());
//i.setBackgroundColor(0Xff000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
return i;
}
});
is.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
is.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
gal=(Gallery) findViewById(R.id.gly);
adapter=new ImageAdapter(this);
gal.setAdapter(adapter);
gal.setOnItemSelectedListener(gaILidstener);
}
private Gallery.OnItemSelectedListener gaILidstener=new Gallery.OnItemSelectedListener() { @Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
is.setImageResource(imgslds[position]);
} @Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub } };
}

ImageAdapter类:

 package com.example.top6_3;

 import android.R.integer;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView; public class ImageAdapter extends BaseAdapter {
private Context context; private static final int[] imgslds={
R.drawable.bjl,
R.drawable.dfhgc,
R.drawable.fg,
R.drawable.gj
};
public ImageAdapter(Context c){
context=c; }
public int getCount() {
// TODO Auto-generated method stub
//
return imgslds.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 iv=new ImageView(context);
iv.setImageResource(imgslds[position]);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setLayoutParams(new Gallery.LayoutParams(,));
//iv.setBackgroundResource(R.drawable.bjl);
return iv; } }

效果图:

Android基础TOP6_3:Gally和ImageSwitcher实现画廊的更多相关文章

  1. Android基础测试题(四)

    看了前两道题大家有没有发现,测试题少了(一),大家猜猜测试题(一)是什么? Android基础测试题(四): 需求: 建一个方法,格式化输出2016-11-14 10:15:26格式的当前时间,然后截 ...

  2. Android基础测试题(二)

    今天给大家带来的是Android基础测试题(二) 题目要求: 定义一个5位长度的整型数组并初始化,然后构建方法根据用户传入的数字判断是否存在数组中,如果存在,返回所在位置,如果不存在,返回-1 首先第 ...

  3. Mono.Android 基础

    Mono.Android 基础 (地址) Mono.Android项目结构是 — Project + Assets + Resources + drawable + layout + values R ...

  4. 深入理解gradle编译-Android基础篇

    深入理解gradle编译-Android基础篇 导读 Gradle基于Groovy的特定领域语言(DSL)编写的一种自动化建构工具,Groovy作为一种高级语言由Java代码实现,本文将对Gradle ...

  5. android基础---->JSON数据的解析

    上篇博客,我们谈到了XML两种常用的解析技术,详细可以参见我的博客(android基础---->XMl数据的解析).网络传输另外一种数据格式JSON就是我们今天要讲的,它是比XML体积更小的数据 ...

  6. 基础4 Android基础

    基础4 Android基础 1. Activity与Fragment的生命周期. Activity生命周期 打开应用 onCreate()->onStart()->onResume 按BA ...

  7. Android基础总结(8)——服务

    服务(Service)是Android中实现程序后台运行的解决方案,它非常适合用于去执行哪些不需要和用户交互而且还要长期运行的任务.服务的运行不依赖任何用户界面,即使当程序被切换到后台,或者用户打开了 ...

  8. 【Xamarin开发 Android 系列 4】 Android 基础知识

    原文:[Xamarin开发 Android 系列 4] Android 基础知识 什么是Android? Android一词的本义指“机器人”,同时也是Google于2007年11月5日宣布的基于Li ...

  9. Android基础_web通信3

    在Android基础_web通信2中,我运用的JSONObject是Android原生的json类,通过import org.json.JSONObject来导入. 还有另外一种更简单的方法,就是用G ...

随机推荐

  1. 类的operator new与operator delete的重载【转】

    http://www.cnblogs.com/luxiaoxun/archive/2012/08/11/2633423.html 为什么有必要写自己的operator new和operator del ...

  2. CentOS command

    管理centos服务器的时候常会对文件进行一些常规操作,除了ftp之外了解在ssh下必要的文件操作命令那也是必不可少的,以下摘录一些常用的文件操作命令: 文件操作: ls ####查看目录中的文件## ...

  3. Centos6.4安装Zimbra初步教程

    环境: 1.centos6.4*64位版本 2.主机最好内存设置在2G以上,要不安装的时候卡死你 3.下载最新的开源的Zimbra安装包,下载zcs-8.0.4_GA_5737.RHEL6_64.20 ...

  4. 走进Struts2(一) — Struts2的执行流程及其工作原理

     Struts2是一套很优秀的Web应用框架,实现优雅.功能强大.使用简洁.能够说是Struts2是一款很成熟的MVC架构. 在我们学习Struts2时,最好是先学习它的执行流程.核心概念.从中得到启 ...

  5. PowerDesinger15设置字体大小

    使用PowerDesigner时,它默认table的字体大小颜色等很难看: 假设通过 Symbol ---> Format进行设置.仅仅能对选中的最改动,新建的Table无效. 能够通过例如以下 ...

  6. openstack-wsgi的route中添加api流程具体解释(os-networks)添加

    感谢朋友支持本博客.欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免.欢迎指正! 如有转载,请保留源作者博客信息. Better Me的博客:blog.csdn.net/tantexian 如需 ...

  7. 嵌入式开发之cmos---前端采集aptina cmos

    http://wenku.baidu.com/link?url=NFl5ye1-o5GNMVGmxBmot1v1HQBOZRA2xo7__sgxxLnpHqodpqtfIW_pf4QNGRX4u8n8 ...

  8. Android WebView开发常见问题

    1.加入权限:AndroidManifest.xml中必须使用许可"android.permission.INTERNET",否则会出Web page not available错 ...

  9. Eclipse Import别人的源代码,出错解决过程

    1.从APKBus上下载了一个源码,想研究一下,结果出错了,经过各种百度,实验,终于解决了,现在记录一下.. File-Import 导入源文件.

  10. CSP 201612-3 权限查询 【模拟+STL】

    201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统用户通过授权 ...