今天周末,祝周末愉快!

先看实例效果:


滑动小图点击后上面的大图就和小图一致了

activity代码:

package com.tmacsky;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.Toast;import android.widget.ViewSwitcher.ViewFactory;public class GalleryActivity extends Activity implements ViewFactory {int index = 0;ImageSwitcher imageSwitcher;int [] image = {R.drawable.ha,R.drawable.hb,R.drawable.hc,R.drawable.hd,R.drawable.he,R.drawable.hf,R.drawable.hg,R.drawable.hh};@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.gallery);//设置imageswitchimageSwitcher = (ImageSwitcher)findViewById(R.id.imageswitcher);//设置一个容器imageSwitcher.setFactory(this);//给一个初始的值imageSwitcher.setImageResource(image[index]);//定义galleryGallery gallery = (Gallery)findViewById(R.id.gallery);//设置adaptergallery.setAdapter(new ImageAdapter());gallery.setOnItemClickListener(new OnItemClickListener() {public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {// TODO Auto-generated method stub//设置滑动后弹出切换图片的数字Toast.makeText(GalleryActivity.this, " " + arg2, 3000).show();imageSwitcher.setImageResource(image[arg2]);}});}class ImageAdapter extends BaseAdapter{public int getCount() {// TODO Auto-generated method stubreturn image.length;}public Object getItem(int position) {// TODO Auto-generated method stubreturn image[position];}public long getItemId(int position) {// TODO Auto-generated method stubreturn image[position];}public View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubImageView imageView = new ImageView(GalleryActivity.this);imageView.setPadding(10, 50, 10, 5);imageView.setImageResource(image[position]);return imageView;}}//设置工厂的时候,系统需要返回一个新的imageview,此处直接是默认的就可以了public View makeView() {// TODO Auto-generated method stubreturn new ImageView(this);}}
gallery.xml的文件代码:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent" android:layout_height="fill_parent"    android:orientation="vertical"    ><ImageSwitcher     android:id="@+id/imageswitcher"    android:background="@drawable/hc"    android:inAnimation="@android:anim/fade_in"    android:outAnimation="@android:anim/fade_out"    android:layout_gravity="center_vertical"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    ></ImageSwitcher><Gallery     android:layout_width="200px"    android:layout_height="wrap_content"    android:id="@+id/gallery"    android:layout_gravity="center_horizontal"     ></Gallery></LinearLayout>

那啥图片资源什么的自己可以找自己喜欢的图,OK~

更多相关文章

  1. ViewPager用法(一)图片+原点+循环播放
  2. Android(安卓)设置TextView滑动滚动条和滑动效果
  3. RelativeLayout布局属性详解
  4. 《Android第一行代码》first reading 十一
  5. Android(安卓)7.0 系统解决拍照的问题 exposed beyond app throu
  6. Android两种 旋转Bitmap方法
  7. 【工具类】如何通过代码安装一个apk文件
  8. Android多点触摸缩放图片-android学习之旅(四)
  9. android中比较两张图片的相似度

随机推荐

  1. 【源码】实现Android闹钟功能使用HTML+JS
  2. Android开发学习 之 五、基本界面控件
  3. 记Android(安卓)Studio自定义属性访问不
  4. 一些非常实用的 Android(安卓)开发资源
  5. Android实现微信和QQ“在其他应用打开”
  6. 【源代码】基于Android和蓝牙的单片机温
  7. Android学习笔记2:Hello World程序解析
  8. Android(安卓)studio 3.0安装配置方法图
  9. Android(安卓)Studio下载及安装3.0版本
  10. ViewGroup 的事件分发核心