K nf IV If tj W sfeatft W in T ft

private Button.OnClickListener image show_button_listerser - new Button.OnClickListener() (

public void onClick(View v) { Intent intent = new Intent();

intent.setClass(MainActivity.this, ImageShowActivity.class); startActivity(intent); I

ffllT'ififrJgiLilf&'fflW. ImageShowActivity, Activity MJiffl^i^/J< ImageSwitcher

&Gallery image show.xml, AJt-'t'^in ImageSwitcher&Gallery,

<?xml version="l.0" encoding="utf-8M?> < Rela t ivc La you t xrnlns : Android="http: //scherr.as . Android. com/apk/res/Android" Android:layout width="fill parent" Android:layout height-"fi11_parent">

< ImageSwi tcher

Android:id="@+id/switcher"

Android:layout width="fill parent" Android:layout height="fi11 parent" Android:layout_alignParentTop="true" Android:layout alignParentLeft="true" />

<Gallery Android:id="@+id/gallery" Android-.background»"« 55000000"

Android:1ayout width="fi1l_parent" Android:layout height="60dp" Android:layout_alignParentBottom="true" Android:layout_alignParentLeft="true" Android:gravity="center_vertical" Android:spacing="16dp" /> </Re1a t i veLa you t >

H immft:

tmWtiiWj£fl:lft. RelativeLayou W^ftW: #9JJB ImageSwithcer ill

Gallery , ImageSwithcer JiJB^ffl^fi^jPtfeEiittSft. Gallery

Wiffift K ImageShow Activity .java tfjiWh, tfftftK onCreate SiBMWin 'FflWs public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState); requestWindcwFeature(Window.FEATURE NO TITLE);

setContentView(R.layout.image_show); setTitle("ImageShowActivity");

mSwitcher = (ImageSwitcher) findViewByld(R.id.switcher); mSwitcher .set-Factory (this) ;

roSwi tcher . setlnAnimat i on (AnimationUt 1 Is . loadAnimation (this,

Android . R . amrri. fade in) ) ; mSwitcher. setOutAniraation (Ani.mat ionUtils. loadAnimation (this, Android.R.anim.fide out)) ;

Gallery g (Gallery) findViewByld(R.id.gallery) ; g.setAdapter(new ImageAdapter(this)); q.setOnltemSelectedListener(this) ;

L-.i^fWl1» request WindowFeature(Window.FEATLJ RE NO TITLE)¿¿ii^J&^h Activity tiilebar. Jit iflJ U" t W ft fc d < I* # £ If? k. Gallery ¡¿^R ill ListView >

setAdaptcr imm&Wo BaseAdapter iittr f MQ, iifiii gctView xX^rfiWlM

jfciMffi1 W.d<il<J Wt Image View flj, get View F0f/J<:

public View getView(int position, View convertView, ViewGroup parent) { ImageView i = new ImageView(mContext); i.setImageResource(mThumblds[position]); i.setAdjustViewBounds(true); i.set I ayoutParams(new Gallery.Layout Params(

Layout Params.WRAP CONTENT, Layout Params.WRAP_CONTSNT)); i.setBackqroundResource(R.drawable.picture frame); return i;

get View Image View, $/S#!jJ4J setLayoutParams > setlmageResource f1l setBackground Resource ft »J iii W ft A *. f*|) V M X it $ I IS ft Yf J8 o ^ ffl ft * % ^ #lj >L| MM 9 M Hi M, Image View o

KlSi«t*UttW ImageSwitcher, /l: ImageSwitcher 1 'P&iH, / ViewSwitcher.ViewFactory ill^teI I. make View. K0W:

public View makeView() {

ImageView i = new ImageView(this);

i.setBackgroundCoior <0xFF000000) ;

.i . setScaleType (ImageView. Sea 1 eType . FIT CENTER) ;

i.setLayoutParams(new ImageSwitcher.LayoutPa rams(LayoutParams.FILL PARENT,

LayoutParams.FILL PARENT)) ; return i;

jAt/jvi^; ImageSwitcher jgNT t View. ImageSwitcher gffc^H

t Factory ft'&tStt-^ View, j&lfi ImageSwitcher Uty&il&WfcM T *

£ it ffl - ^ ImageSwitcher ^ > - 11 ffl setFactory £ , £ M , : setlmageResource ^ # & £ ft # K?.ImageSwitcher It/" A J ffi

JP}±It j sctlnAnimation $AImageSwitcher t j It ft *, setOutAnimation £ $ X itImageSwitcher 1 $ & ft' M M « £

fikAiff. AndroidManifest.xml ifM'^An*]"® Activity iM'it. 'itfiMWlill Flfr/j<:

LROas

<activity

Android: name=" ImageShowAet i vity"x/acti vity> Mi j'ii^^^Jfi'/T', {W l-.Vflfll .inmageSwitcher Gallery",

Grid View fete f««. "i A ® 7'33 I^SwTtcher fa Gallery ^^

•ft. ff^Amain.xml ifhl'^Sn-^ "GridView" ftftl. ^SMWiUl F0PJ*s

<Button Android: id=,,@ + id/grid_viev/ button" Android:layout_width="wrap_content" Android: layout height="wrap_cont.erit" Android:text="Gridview"/>

&SL tiOj "grid view button" tfy&m, "CiridView"«

private Button.OnClickListener grid viewbutton listener - new Button.OnClickListener() {

public void onClick(View v) ( Intent intent = new Intent();

intent.setClass(MainActivity.this, GridViewActivity.class);

startActivity(intent); >

\immft:

Mttm GridViewActivityo JR/gft & onCreate #

ifc+iSjtaiU vim-.

public void onCreate(Bundle savedlnstanceState) ( super .onCreate (savedInstanceState) ; setContentView(R.layout.grid view); setTitle("GridViewActivity");

GridView gridview (GridView) tindViewByld<R.id.grid view); gridview.setAdapter(new ImageAdapter(this));

I J£fWttftm'ALimticSCtWj grid view.xml, *SB«JR«iR + W GridView ffifh IJ

setAdapter -tififfi ImageAdapter0TImageAdapter fttoM&iM,

public class ImageAdapter extends BaseAdapter private Context mContext;

public ImageAdapter(Context c> ( mContext - c;

public int cjetCountO (

return mThumblds.length;

public Object get I tern (int position) i return null;

public long getltemld(int position) return 0;

public View getViewiint position, View convertView, ViewGroup parent) ( ImageView imageView;

if (convertView~null) ( // if it's not recycled,initialize some attributes imageView = new ImageView(mContext} ;

imageView.setLayoutParams(new GridView.LayoutParams(8b, 8b)); imageView.setScaleType(ImageView.ScaleType.CENTER CROP); imageView.setPadding(8, 8, 8, 8); ) else {

imageView ^ (ImageView) convertView;

i mageView.setlmageResource(mThumblds[pos_ t ion 1); return imageView;

private Integerf" mThumblds -R.drawable.grid view R.drawabie.grid view R.drawable.gridview R.drawab Le.gri d view R.drawable.gri d_view R.drawab Le.grid view R.drawable.grid_view R.drawable.grid_view R.drawable.sample 2, R.drawable.sample_4, R.drawable.sample 6,

01, R.drawable.grid_view_02, 0 3, R.drawable.grid view 04, Ob, R.drawable.gridview 06, 07, R.drawable.gridview 08, 09, R.drawable.gr id_ view 10, 11, R.drawable.grid_view_12, 13, R.drawab1e.grid view 14, lb, R.drawable.sample 1, R . drawable . sarnple_3, R.drawable.sample 5, R.drawable.sampleV

ImageAdapter J * BaseAdapter. Jj'tt. ImageAdapter ¿fcifr

Context, j&fnfc'gttiJi get View ImageView, Jj

S £ *f J® (ft Wit . mThumblds WL & SB 22 M ffl H IV p Kluft AndroidManifest.xmJ 'I'ipjJll Activity fftrfiiu, I Kifrd<:

<ac t i vi t. y Android: name = "Gr idVi e wAct i v i t y " ></ac t. i vi t. y > ¡¿'it^Wiftr tti^ffii tf-S "GridViewfig/jeffi) GridView Activity MKtom 7-34 f9f >J<.

Was this article helpful?

0 0

Post a comment