Android 控件之ImageSwitcher图片切换器

ImageSwitcher是Android中控制图片展示效果的一个控件,如:幻灯片效果...,颇有感觉啊。做相册一绝

Android 控件之ImageSwitcher图片切换器

Android 控件之ImageSwitcher图片切换器源码下载

免费下载地址在

用户名与密码都是

具体下载目录在 /2012年资料/2月/2日/Android 控件之ImageSwitcher图片切换器/ 

一、重要方法

    setImageURI(Uri uri):设置图片地址

    setImageResource(int resid):设置图片资源库

    setImageDrawable(Drawable drawable):绘制图片

二、实例

   <ImageSwitcher android:id="@+id/switcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
    />
   
    <Gallery android: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"
    />

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));

  

三、完整代码

1.布局文件

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <ImageSwitcher android:id="@+id/switcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
    />
   
    <Gallery android: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>
   2.Java代码

package wjq.WidgetDemo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Gallery.LayoutParams;
import android.widget.ViewSwitcher.ViewFactory;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wygjpg.html