天天看點

Android 中文 API (35) —— ImageSwitcher

前言

聲明

  歡迎轉載,但請保留文章原始出處:) 

正文

  一、結構

    public class imageswitcher extends viewswitcher

    java.lang.object

        android.view.viewgroup

          android.widget.framelayout

            android.widget.viewanimator

              android.widget.viewswitcher

                android.widget.imageswitcher

  二、概述

    

Android 中文 API (35) —— ImageSwitcher

    (譯者注:imageswitcher是android中控制圖檔展示效果的一個控件,如:幻燈片效果...,頗有感覺啊,做相冊一絕。)

  三、公共方法

         public void setimagedrawable (drawable drawable)

         繪制圖檔

 public void setimageresource (int resid)

   設定圖檔資源庫

 public void setimageuri (uri uri)

  設定圖檔位址

  四、補充

    4.1  文章連結

      java檔案

Android 中文 API (35) —— ImageSwitcher

public class mainactivity extends activity implements

  onitemselectedlistener, viewfactory {

 private imageswitcher is;

 private gallery gallery;

 private integer[] mthumbids = { r.drawable.b, r.drawable.c,

   r.drawable.d, r.drawable.f, r.drawable.g,

   };

 private integer[] mimageids = { r.drawable.b, r.drawable.c,

   r.drawable.d, r.drawable.f, r.drawable.g, };

@override

 protected void oncreate(bundle savedinstancestate) {

  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(new imageadapter(this));

  gallery.setonitemselectedlistener(this);

 }

 @override

 public view makeview() {

  imageview i = new imageview(this);

  i.setbackgroundcolor(0xff000000);

  i.setscaletype(imageview.scaletype.fit_center);

  i.setlayoutparams(new imageswitcher.layoutparams(

    layoutparams.match_parent, layoutparams.match_parent));

  return i;

 public class imageadapter extends baseadapter {

  public imageadapter(context c) {

   mcontext = c;

  }

  public int getcount() {

   return mthumbids.length;

  public object getitem(int position) {

   return position;

  public long getitemid(int position) {

  public view getview(int position, view convertview, viewgroup parent) {

   imageview i = new imageview(mcontext);

   i.setimageresource(mthumbids[position]);

   i.setadjustviewbounds(true);

   i.setlayoutparams(new gallery.layoutparams(

     layoutparams.wrap_content, layoutparams.wrap_content));

   i.setbackgroundresource(r.drawable.e);

   return i;

  private context mcontext;

 public void onitemselected(adapterview<?> parent, view view, int position,

   long id) {

  is.setimageresource(mimageids[position]);

 public void onnothingselected(adapterview<?> parent) {

}

Android 中文 API (35) —— ImageSwitcher

      xml檔案

Android 中文 API (35) —— ImageSwitcher

<?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_height="60dp"

        android:layout_alignparentbottom="true"

        android:gravity="center_vertical"

        android:spacing="16dp"

</relativelayout>

Android 中文 API (35) —— ImageSwitcher

結束

   wallace2010居然弄個這麼好看的圖檔 - - #  吸引帝......

轉載:http://www.cnblogs.com/over140/archive/2010/11/11/1874932.html

繼續閱讀