声明

  欢迎转载,但请保留文章原始出处:)

    博客园:http://www.cnblogs.com/

    Android中文翻译组:http://www.cnblogs.com/over140/

正文

  一、结构

    public classImageSwitcherextendsViewSwitcher


    java.lang.Object
      android.view.View
        android.view.ViewGroup
          android.widget.FrameLayout
            android.widget.ViewAnimator
              android.widget.ViewSwitcher
                android.widget.ImageSwitcher

  二、概述

    Android 中文 API —— ImageSwitcher,Gallery

    (译者注:ImageSwitcherAndroid中控制图片展示效果的一个控件,如:幻灯片效果...,颇有感觉啊,做相册一绝。)

  三、公共方法

public void setImageDrawable (Drawable drawable)

绘制图片

 public void setImageResource (int resid)

设置图片资源库

 public void setImageURI (Uri uri)

设置图片地址

  四、补充

    4.1  文章链接

Android ImageSwitcher

Image Switcher View | Android Developer Tutorial

    4.2  示例代码本文代码转载自这里

      java文件

复制代码

publicclassmainactivityextendsActivityimplements
OnItemSelectedListener,ViewFactory{
privateImageSwitcheris;
privateGallerygallery;

privateInteger[]mThumbIds={R.drawable.b,R.drawable.c,
R.drawable.d,R.drawable.f,R.drawable.g,
};

privateInteger[]mImageIds={R.drawable.b,R.drawable.c,
R.drawable.d,R.drawable.f,R.drawable.g,};

@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

is
=(ImageSwitcher)findViewById(R.id.switcher);
is.setFactory(
this);

is.setInAnimation(AnimationUtils.loadAnimation(
this,
android.R.anim.fade_in));
is.setOutAnimation(AnimationUtils.loadAnimation(
this,
android.R.anim.fade_out));

gallery
=(Gallery)findViewById(R.id.gallery);

gallery.setAdapter(
newImageAdapter(this));
gallery.setOnItemSelectedListener(
this);
}

@Override
publicViewmakeView(){
ImageViewi
=newImageView(this);
i.setBackgroundColor(
0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(
newImageSwitcher.LayoutParams(
LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
returni;
}

publicclassImageAdapterextendsBaseAdapter{
publicImageAdapter(Contextc){
mContext
=c;
}

publicintgetCount(){
returnmThumbIds.length;
}

publicObjectgetItem(intposition){
returnposition;
}

publiclonggetItemId(intposition){
returnposition;
}

publicViewgetView(intposition,ViewconvertView,ViewGroupparent){
ImageViewi
=newImageView(mContext);

i.setImageResource(mThumbIds[position]);
i.setAdjustViewBounds(
true);
i.setLayoutParams(
newGallery.LayoutParams(
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
i.setBackgroundResource(R.drawable.e);
returni;
}

privateContextmContext;

}

@Override
publicvoidonItemSelected(AdapterView<?>parent,Viewview,intposition,
longid){
is.setImageResource(mImageIds[position]);

}

@Override
publicvoidonNothingSelected(AdapterView<?>parent){
}
}

复制代码

      xml文件

复制代码

<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width
="match_parent"
android:layout_height
="match_parent">

<ImageSwitcherandroid:id="@+id/switcher"
android:layout_width
="match_parent"
android:layout_height
="match_parent"
android:layout_alignParentTop
="true"
android:layout_alignParentLeft
="true"
/>

<Galleryandroid:id="@+id/gallery"
android:background
="#55000000"
android:layout_width
="match_parent"
android:layout_height
="60dp"
android:layout_alignParentBottom
="true"
android:layout_alignParentLeft
="true"

android:gravity
="center_vertical"
android:spacing
="16dp"
/>
</RelativeLayout>

复制代码

结束

  

更多相关文章

  1. Android 标题下的内容折叠效果
  2. Android 实现九宫格、点击图片放大全屏浏览等
  3. Android中启动第三方程序的代码
  4. Android 界面淡出 淡入效果
  5. Android之Uri转化为Bitmap,一行代码
  6. Android ImageView图片浏览器(ImageView加载sd卡图片资源)的内存溢
  7. android实现点击图片全屏展示效果
  8. Android 动画效果学习笔记
  9. Android ScrollView HorizontalScrollView 实现全方向(上下左右)

随机推荐

  1. Android五层架构
  2. Android(安卓)异步加载解决方案
  3. android中ListView点击和ListView的item
  4. Android之消息推送实现
  5. android switch模块
  6. [Android]文本框实现搜索和清空效果
  7. android的Handler
  8. 新手拥抱Android
  9. 理解 Android(安卓)Build 系统
  10. 中国Android应用商店汇总介绍