SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler offline
݇†ó£Œ®™ ðìƒè¬÷ ¬èò£À
õ ðô º¬øèœ àœ÷ù. ÜõŸ
Áœ å¼ º¬ø «èôK (Gallery) ðò¡ð´ˆ¶
õ‹.
ºîL™ «èôK â¡ø Šó£ªü‚†®¬ù
à¼õ£‚è «õ‡´‹. Þ‰î Šó£ªü‚†®¡
«ï£‚è‹ å¼ Cô ðìƒè¬÷ õK¬êò£è
F¬óJ™ 裇Hˆ¶, ãî£õ¶ ðìˆF¬ù
AO‚ ªêŒî¾ì¡ F¬óJ™ îèõL¬ù
裇HŠð«îò£°‹. ÜŠO«èû¡ â‚OŠv
ªè£‡´ à¼õ£‚°A«ø£‹.
â‚OŠvC™ à¼õ£‚èŠð´‹ ÜŠO«èê¡
è¬÷ å¼ å˜‚v«ðC™ (Work Space) «êIˆ¶
¬õ‚°‹. â¡Â¬ìò ÜŠO«èê¡èœ âù¶
èEQJ™ C:usersmeeraneelaworkspace
â¡ø ç«ð£™ìK™ «êI‚èŠð´A¡øù.
(ðì‹-1). à¼õ£‚èŠð´‹ Šó£ªü‚†´èœ
ç«ð£™ìó£è «êI‚èŠð´‹. Þƒ° Gallery
â¡ø ç«ð£™ì˜ Þ¼Šðî¬ù è£íô£‹.
Gallery/res â¡ø ç«ð£™ìK¬ù à¼õ£‚A
Sample.jpg, Sample2.jpg,sample3.jpg,sample4.
jpg,sample5.jpg,sample6.jpg ñŸÁ‹ Sample
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
ðì‹-1
ðì‹-2
Gó™-1
ðìƒè¬÷
¬èò£À‹
«èôK!
Ý¡†ó£Œ´ -2
Þ󣋰ñ£˜ ªô†²Iï£ó£òí¡
15
7.jpg â¡Á ªðò¼¬ìò ðìƒè¬÷ «êIˆ
F´ƒèœ. (ðì‹-2)
Ü´ˆîî£è «èôK ÝŠªü‚†®¬ù main.
xml -™ ðò¡ð´ˆî «õ‡´‹. main.xml-Ÿ
è£ù¶ Gó™ -1-™ àœ÷¶ «ð£¡Á Þ¼‚°‹.
Ü´ˆîî£è Šó£ªü‚† à¼õ£‚èŠð†ì
¾ì¡ «î£¡P»œ÷ Gallery Activity.java
ç¬ðL™ àœ÷ OnCreate ªñˆî®™ Gó™-2™
àœ÷¶ «ð£¡Á Gó™è¬÷ Þ¬í‚è «õ‡
´‹.
ºîL™ main.xml-™ àœ÷ «ôܾ†®¬ù
Content View â¡Á ܬñ‚A«ø£‹.
Ü´ˆîî£è «èôK ÝŠªü‚†®¬ù find
viewById(R.id.gallery) ðò¡ð´ˆF «ôܾ†´
ì¡ Þ¬íˆFì «õ‡´‹. «èôKJ™ ðò¡
𴈶õîŸè£è BaseAdapter å¡P¬ù à¼
õ£‚è «ð£A«ø£‹. Üî¡ ªðò˜ Image
Adapter â¡ð‹.
Ü´ˆîî£è «èôKJ™ SetOnItemClick
Listener ðò¡ð´ˆF AO‚ ªêŒõîù£™
îèõ™ F¬óJ™ «î£¡Áñ£Á ܬñˆ¶œ
«÷£‹. îèõ™ F¬óJ™ 裇H‚è Toast ðò¡
ð´ˆîŠð†´œ÷¶.
Ü´ˆîî£è «èôKJ™ ðò¡ð´ˆîŠð´‹
v¬ìL¬ù (Style) °PŠH´õîŸè£è attrs.
xml â¡ø Xml ç¬ðL¬ù ðò¡ð´ˆî «ð£A
«ø£‹. attrs.xml-Ÿè£ù Gó™ -3™ ªè£´‚
Gallery gallery = (Gallery)findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new onItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
Toast.makeText(GalleryActivity.this,""+ position, Toast.LENGTH_SHORT).show();
}} );
<?xml version="1.0" encoding="utf-
8"?>
<resources>
<declare-styleable
name="HelloGallery">
<attr
name="android:galleryItemBackground
"/>
</declare-styleable>
</resources>
èŠð†´œ÷¶. <attr> âLªñ¡† Íô‹
v“L android.gallery ItemBack ground
â¡Á °PŠH†´œ«÷£‹.
Ü´ˆîî£è ImageAdapter.java â¡ø
ç¬ðL¬ù à¼õ£‚è «õ‡´‹. à¼õ£‚èŠ
𴋫𣶠«ðv Ü죊ìK¬ù (Base
Adapter) Extend ªêŒò «õ‡´‹. (Gó™-4)
Array- J¬ù ªè£‡´ drawable Folder- ™
ެ특 ãŸð´ˆî «õ‡´‹. Ü´ˆîî£è
Class Constructor ðò¡ð´ˆîŠð†´œ÷¶.
Gó™-2
Gó™-3
ðì‹-3
ðì‹-4
package ram.com.gallery;
import android.content.Context;
import android.content.res.TypedArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class ImageAdapter extends
BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds ={
R.drawable.sample1,
R.drawable.sample2,
R.drawable.sample3,
R.drawable.sample4,
R.drawable.sample5,
R.drawable.sample6,
R.drawable.sample7
};
public ImageAdapter(Context c){
mContext = c;
TypedArray attr =
mContext.obtainStyledAttributes(R.styleab
le.HelloGallery);
mGalleryItemBackground =
attr.getResourceId(R.styleable.HelloGaller
y_android_galleryItemBackground, 0);
attr.recycle();
}
@Override
public int getCount() {
// TODO Auto-generated method
stub
return mImageIds.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method
stub
return mImageIds[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method
stub
return mImageIds[position];
}
@Override
public View getView(int position, View
convertView, ViewGroup parent) {
// TODO Auto-generated method
stub
ImageView imageView = new
ImageView(mContext);
imageView.setImageResource(mImageIds
[position]);
imageView.setLayoutParams(new
Gallery.LayoutParams(150,100));
imageView.setScaleType(ImageView.Scal
eType.FIT_XY);
imageView.setBackgroundResource(mGall
eryItemBackground);
return imageView;
}
}
Gó™-4
Þƒ° Þ«ñx Ü죊켂
è£ù Context õ¬óòÁ‚èŠ
ð†´œ÷¶. Ü´ˆîî£è style
able resource â¡ðî¬ù attr
â¡ø çd™´ (Field) Íô‹
°PŠHìŠ ð†´œ÷¶.
Constructor- ¡ º®M™ Typed
Array -J¬ù ®¬õv e‡´‹
ðò¡ð´ˆîô£‹ â¡ðîŸè£è
recycle() ðò¡ð´ˆîŠð†
´œ÷¶.
Þ«ñT¬ù «èôK»ì¡
ެ특 ãŸð´ˆ¶õ
getCount(),getItem() ñŸÁ‹
getIte mId() ªñˆî†èœ ðò¡
ð´ˆîŠð†´œ÷¶. getview
ªñˆî† Íô‹ ContextMember
Íô‹ Þ«ñx MÎ à¼õ£‚èŠ
ð†´œ÷¶.
Þ«ñx MÎMŸ° drawble-
L™ àœ÷ ðìƒèÀì¡
ެ특 ãŸð´ˆîŠð†´œ
֦.
imageView.setImageResourc
e(mImageIds [position];
Þ«ñx MÎM¡ c÷ ñŸÁ‹
ÜèôˆF¬ù Gallery.Layout
params Íô‹ °PŠH†´œ
«÷£‹.
ðì‹-6ðì‹-5
- ªî£ì¼‹
i m a g e V i e w . S e t L a y o u t
Params (new Gallery. Layout
Params(150,100);
Þî¬ù «ð£¡«ø,
SetScaleType ñŸÁ‹ SetBack
groundResource ðò¡ð´ˆîŠ
ð†´œ÷¶. ÜŠO«èê¬ù
ªêò™ð´ˆ¶õ ºîL™
Project-Build Project â¡ð
î¬ù AO‚ ªêŒò «õ‡´‹.
H¬öèœ ã«î‹ Þ¼‰î£™
Þ‰î ªêò™ Íô‹ ÜP‰¶
ªè£œ÷ô£‹.
Ü´ˆîî£è «èôK â¡ø
Šó£ªü‚†®¬ù «î˜¾
ªêŒ¶ Run As>Android Appli
cation â¡Á AO‚ ªêŒò
«õ‡´‹. (ðì‹-3)
Run As> Android Application
â¡ðî¬ù «î˜¾ ªêŒî¾ì¡
ðì‹-4™ àœ÷¶ «ð£¡Á
«î£¡Á‹. «î¬õò£ù âº
«ô†ìK¬ù«ò£ (Emulator)
Ü™ô¶ ®¬õC¬ù«ò£
«î˜‰ ªî´ˆ¶ ªè£œ÷ô£‹.
«èôK ÜŠO«èê¡ ðì‹-5™
àœ÷¶ «ð£¡Á F¬óJ™
«î£¡Á‹ ðìˆF¬ù
®¬õvªî£´F¬óJ™ªî£†
죙 ðìˆF¡ ⇠F¬óJ™
«î£¡Á‹. (ðì‹-6)

Mais conteúdo relacionado

Mais procurados

「レガシーコード」とはいったい?
「レガシーコード」とはいったい?「レガシーコード」とはいったい?
「レガシーコード」とはいったい?Hiroyuki Ohnaka
 
Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)Dr. Ramkumar Lakshminarayanan
 
プログラマのためのテスト2
プログラマのためのテスト2プログラマのためのテスト2
プログラマのためのテスト2Kuniaki Igarashi
 
KGC2007 Scrum And Xp
KGC2007 Scrum And XpKGC2007 Scrum And Xp
KGC2007 Scrum And Xp기룡 남
 
Sharh Hadeeth Jibreel
Sharh Hadeeth JibreelSharh Hadeeth Jibreel
Sharh Hadeeth JibreelZaffer Khan
 
Novell Proposal To Atos Major Events 07 12 2009
Novell Proposal To Atos Major Events   07 12 2009Novell Proposal To Atos Major Events   07 12 2009
Novell Proposal To Atos Major Events 07 12 2009petercadejong
 
umrah ka asan tariqa (hanfi) by Dr.hafiz Muhammad naeem
umrah ka asan tariqa (hanfi)  by Dr.hafiz  Muhammad naeemumrah ka asan tariqa (hanfi)  by Dr.hafiz  Muhammad naeem
umrah ka asan tariqa (hanfi) by Dr.hafiz Muhammad naeemMadiha latif
 
secrets of teeth whitening
secrets of teeth whiteningsecrets of teeth whitening
secrets of teeth whitening2119Anna
 
패턴 스터디 발표 자료 - State 패턴
패턴 스터디 발표 자료 - State 패턴패턴 스터디 발표 자료 - State 패턴
패턴 스터디 발표 자료 - State 패턴beom kyun choi
 
دعوت اسلامی کا تعارف
دعوت اسلامی کا تعارفدعوت اسلامی کا تعارف
دعوت اسلامی کا تعارفdawateislami
 

Mais procurados (20)

Sample Add Application uisng Android (in tamil)
Sample Add Application uisng Android (in tamil)Sample Add Application uisng Android (in tamil)
Sample Add Application uisng Android (in tamil)
 
Installing Eclipse (in tamil)
Installing Eclipse (in tamil)Installing Eclipse (in tamil)
Installing Eclipse (in tamil)
 
Lekts11
Lekts11Lekts11
Lekts11
 
Create and Sell Android App (in tamil)
Create and Sell Android App (in tamil)Create and Sell Android App (in tamil)
Create and Sell Android App (in tamil)
 
Android Application using seekbar (in tamil)
Android Application using seekbar (in tamil)Android Application using seekbar (in tamil)
Android Application using seekbar (in tamil)
 
「レガシーコード」とはいったい?
「レガシーコード」とはいったい?「レガシーコード」とはいったい?
「レガシーコード」とはいったい?
 
Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)
 
プログラマのためのテスト2
プログラマのためのテスト2プログラマのためのテスト2
プログラマのためのテスト2
 
Android app - Creating Live Wallpaper (tamil)
Android app - Creating Live Wallpaper (tamil)Android app - Creating Live Wallpaper (tamil)
Android app - Creating Live Wallpaper (tamil)
 
KGC2007 Scrum And Xp
KGC2007 Scrum And XpKGC2007 Scrum And Xp
KGC2007 Scrum And Xp
 
Sharh Hadeeth Jibreel
Sharh Hadeeth JibreelSharh Hadeeth Jibreel
Sharh Hadeeth Jibreel
 
jQuery Tutorial
jQuery TutorialjQuery Tutorial
jQuery Tutorial
 
jQuery
jQueryjQuery
jQuery
 
Novell Proposal To Atos Major Events 07 12 2009
Novell Proposal To Atos Major Events   07 12 2009Novell Proposal To Atos Major Events   07 12 2009
Novell Proposal To Atos Major Events 07 12 2009
 
umrah ka asan tariqa (hanfi) by Dr.hafiz Muhammad naeem
umrah ka asan tariqa (hanfi)  by Dr.hafiz  Muhammad naeemumrah ka asan tariqa (hanfi)  by Dr.hafiz  Muhammad naeem
umrah ka asan tariqa (hanfi) by Dr.hafiz Muhammad naeem
 
Pseudo Perl
Pseudo PerlPseudo Perl
Pseudo Perl
 
Pseudo Block
Pseudo BlockPseudo Block
Pseudo Block
 
secrets of teeth whitening
secrets of teeth whiteningsecrets of teeth whitening
secrets of teeth whitening
 
패턴 스터디 발표 자료 - State 패턴
패턴 스터디 발표 자료 - State 패턴패턴 스터디 발표 자료 - State 패턴
패턴 스터디 발표 자료 - State 패턴
 
دعوت اسلامی کا تعارف
دعوت اسلامی کا تعارفدعوت اسلامی کا تعارف
دعوت اسلامی کا تعارف
 

Destaque

Uso de dispositivos moviles en la enseñanza
Uso de dispositivos moviles en la enseñanzaUso de dispositivos moviles en la enseñanza
Uso de dispositivos moviles en la enseñanzaRomeo Clará
 
Rolas en El Mañanero.
Rolas en El Mañanero.Rolas en El Mañanero.
Rolas en El Mañanero.Brozo Xmiswebs
 
Sailing ficha insc + cartaz
Sailing ficha insc + cartazSailing ficha insc + cartaz
Sailing ficha insc + cartazsstab
 
What was it like releasing your first album
What was it like releasing your first albumWhat was it like releasing your first album
What was it like releasing your first albumchloewhittle2
 
Hormigueros%20es%20un%20municipio%20localizado%20al%20oeste%20del%20 estado%2...
Hormigueros%20es%20un%20municipio%20localizado%20al%20oeste%20del%20 estado%2...Hormigueros%20es%20un%20municipio%20localizado%20al%20oeste%20del%20 estado%2...
Hormigueros%20es%20un%20municipio%20localizado%20al%20oeste%20del%20 estado%2...mortallife
 
Res gasoductos
Res gasoductosRes gasoductos
Res gasoductosromandav
 
Afiche proyecto de ley universitaria danimar castillo eglee_castro
Afiche proyecto de ley universitaria danimar castillo eglee_castroAfiche proyecto de ley universitaria danimar castillo eglee_castro
Afiche proyecto de ley universitaria danimar castillo eglee_castroDanimar Castillo
 
Reihane
ReihaneReihane
Reihanefshiri
 
Papeleria corporativa
Papeleria corporativaPapeleria corporativa
Papeleria corporativajorgecaste27
 
Segunda guerra mundial
Segunda guerra mundialSegunda guerra mundial
Segunda guerra mundialpapiestamuerto
 
Juego conociendo a los animales
Juego conociendo a los animalesJuego conociendo a los animales
Juego conociendo a los animalesMike Vêga
 
El conocimieto maryleen
El conocimieto  maryleenEl conocimieto  maryleen
El conocimieto maryleenmaryleen1995
 
Diapositva de educacion civica (formacion civica (2)
Diapositva de educacion  civica  (formacion civica (2)Diapositva de educacion  civica  (formacion civica (2)
Diapositva de educacion civica (formacion civica (2)Luz Aleida Valdez Vasquez
 
Recursos educativos con soporte virtual
Recursos educativos con soporte virtualRecursos educativos con soporte virtual
Recursos educativos con soporte virtualNormaRodriguezP
 

Destaque (20)

Uso de dispositivos moviles en la enseñanza
Uso de dispositivos moviles en la enseñanzaUso de dispositivos moviles en la enseñanza
Uso de dispositivos moviles en la enseñanza
 
Business
BusinessBusiness
Business
 
Rolas en El Mañanero.
Rolas en El Mañanero.Rolas en El Mañanero.
Rolas en El Mañanero.
 
Sailing ficha insc + cartaz
Sailing ficha insc + cartazSailing ficha insc + cartaz
Sailing ficha insc + cartaz
 
What was it like releasing your first album
What was it like releasing your first albumWhat was it like releasing your first album
What was it like releasing your first album
 
Hormigueros%20es%20un%20municipio%20localizado%20al%20oeste%20del%20 estado%2...
Hormigueros%20es%20un%20municipio%20localizado%20al%20oeste%20del%20 estado%2...Hormigueros%20es%20un%20municipio%20localizado%20al%20oeste%20del%20 estado%2...
Hormigueros%20es%20un%20municipio%20localizado%20al%20oeste%20del%20 estado%2...
 
Res gasoductos
Res gasoductosRes gasoductos
Res gasoductos
 
Manual abaco
Manual abacoManual abaco
Manual abaco
 
Afiche proyecto de ley universitaria danimar castillo eglee_castro
Afiche proyecto de ley universitaria danimar castillo eglee_castroAfiche proyecto de ley universitaria danimar castillo eglee_castro
Afiche proyecto de ley universitaria danimar castillo eglee_castro
 
Activitati culturale
Activitati culturaleActivitati culturale
Activitati culturale
 
Reihane
ReihaneReihane
Reihane
 
Papeleria corporativa
Papeleria corporativaPapeleria corporativa
Papeleria corporativa
 
Segunda guerra mundial
Segunda guerra mundialSegunda guerra mundial
Segunda guerra mundial
 
Juego conociendo a los animales
Juego conociendo a los animalesJuego conociendo a los animales
Juego conociendo a los animales
 
MEDICINA
MEDICINAMEDICINA
MEDICINA
 
El conocimieto maryleen
El conocimieto  maryleenEl conocimieto  maryleen
El conocimieto maryleen
 
Diapositva de educacion civica (formacion civica (2)
Diapositva de educacion  civica  (formacion civica (2)Diapositva de educacion  civica  (formacion civica (2)
Diapositva de educacion civica (formacion civica (2)
 
Recursos educativos con soporte virtual
Recursos educativos con soporte virtualRecursos educativos con soporte virtual
Recursos educativos con soporte virtual
 
Mithilesh-CV
Mithilesh-CVMithilesh-CV
Mithilesh-CV
 
Sex
SexSex
Sex
 

Mais de Dr. Ramkumar Lakshminarayanan (17)

IT security awareness
IT security awarenessIT security awareness
IT security awareness
 
Basics of IT security
Basics of IT securityBasics of IT security
Basics of IT security
 
IT Security Awareness Posters
IT Security Awareness PostersIT Security Awareness Posters
IT Security Awareness Posters
 
Normalisation revision
Normalisation revisionNormalisation revision
Normalisation revision
 
Windows mobile programming
Windows mobile programmingWindows mobile programming
Windows mobile programming
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Web technology today
Web technology todayWeb technology today
Web technology today
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Phonegap for Android
Phonegap for AndroidPhonegap for Android
Phonegap for Android
 
Android Tips (Tamil)
Android Tips (Tamil)Android Tips (Tamil)
Android Tips (Tamil)
 
Android Animation (in tamil)
Android Animation (in tamil)Android Animation (in tamil)
Android Animation (in tamil)
 
Single Touch event view in Android (in tamil)
Single Touch event view in Android (in tamil)Single Touch event view in Android (in tamil)
Single Touch event view in Android (in tamil)
 
GPS in Android (in tamil)
GPS in Android (in tamil)GPS in Android (in tamil)
GPS in Android (in tamil)
 
Data Storage in Android App
Data Storage in Android AppData Storage in Android App
Data Storage in Android App
 
Part 7
Part 7Part 7
Part 7
 
Notification in Android App (in tamil)
Notification in Android App (in tamil)Notification in Android App (in tamil)
Notification in Android App (in tamil)
 
Layout Object in Android App
Layout Object in Android AppLayout Object in Android App
Layout Object in Android App
 

Creating Image Gallery - Android app (in tamil)

  • 1. ݇†ó£Œ®™ ðìƒè¬÷ ¬èò£À õ ðô º¬øèœ àœ÷ù. ÜõŸ Áœ å¼ º¬ø «èôK (Gallery) ðò¡ð´ˆ¶ õ‹. ºîL™ «èôK â¡ø Šó£ªü‚†®¬ù à¼õ£‚è «õ‡´‹. Þ‰î Šó£ªü‚†®¡ «ï£‚è‹ å¼ Cô ðìƒè¬÷ õK¬êò£è F¬óJ™ 裇Hˆ¶, ãî£õ¶ ðìˆF¬ù AO‚ ªêŒî¾ì¡ F¬óJ™ îèõL¬ù 裇HŠð«îò£°‹. ÜŠO«èû¡ â‚OŠv ªè£‡´ à¼õ£‚°A«ø£‹. â‚OŠvC™ à¼õ£‚èŠð´‹ ÜŠO«èê¡ è¬÷ å¼ å˜‚v«ðC™ (Work Space) «êIˆ¶ ¬õ‚°‹. â¡Â¬ìò ÜŠO«èê¡èœ âù¶ èEQJ™ C:usersmeeraneelaworkspace â¡ø ç«ð£™ìK™ «êI‚èŠð´A¡øù. (ðì‹-1). à¼õ£‚èŠð´‹ Šó£ªü‚†´èœ ç«ð£™ìó£è «êI‚èŠð´‹. Þƒ° Gallery â¡ø ç«ð£™ì˜ Þ¼Šðî¬ù è£íô£‹. Gallery/res â¡ø ç«ð£™ìK¬ù à¼õ£‚A Sample.jpg, Sample2.jpg,sample3.jpg,sample4. jpg,sample5.jpg,sample6.jpg ñŸÁ‹ Sample <?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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ðì‹-1 ðì‹-2 Gó™-1 ðìƒè¬÷ ¬èò£À‹ «èôK!
  • 2. Ý¡†ó£Œ´ -2 Þ󣋰ñ£˜ ªô†²Iï£ó£òí¡ 15 7.jpg â¡Á ªðò¼¬ìò ðìƒè¬÷ «êIˆ F´ƒèœ. (ðì‹-2) Ü´ˆîî£è «èôK ÝŠªü‚†®¬ù main. xml -™ ðò¡ð´ˆî «õ‡´‹. main.xml-Ÿ è£ù¶ Gó™ -1-™ àœ÷¶ «ð£¡Á Þ¼‚°‹. Ü´ˆîî£è Šó£ªü‚† à¼õ£‚èŠð†ì ¾ì¡ «î£¡P»œ÷ Gallery Activity.java ç¬ðL™ àœ÷ OnCreate ªñˆî®™ Gó™-2™ àœ÷¶ «ð£¡Á Gó™è¬÷ Þ¬í‚è «õ‡ ´‹. ºîL™ main.xml-™ àœ÷ «ôܾ†®¬ù Content View â¡Á ܬñ‚A«ø£‹. Ü´ˆîî£è «èôK ÝŠªü‚†®¬ù find viewById(R.id.gallery) ðò¡ð´ˆF «ôܾ†´ ì¡ Þ¬íˆFì «õ‡´‹. «èôKJ™ ðò¡ 𴈶õîŸè£è BaseAdapter å¡P¬ù ༠õ£‚è «ð£A«ø£‹. Üî¡ ªðò˜ Image Adapter â¡ð‹. Ü´ˆîî£è «èôKJ™ SetOnItemClick Listener ðò¡ð´ˆF AO‚ ªêŒõîù£™ îèõ™ F¬óJ™ «î£¡Áñ£Á ܬñˆ¶œ «÷£‹. îèõ™ F¬óJ™ 裇H‚è Toast ðò¡ ð´ˆîŠð†´œ÷¶. Ü´ˆîî£è «èôKJ™ ðò¡ð´ˆîŠð´‹ v¬ìL¬ù (Style) °PŠH´õîŸè£è attrs. xml â¡ø Xml ç¬ðL¬ù ðò¡ð´ˆî «ð£A «ø£‹. attrs.xml-Ÿè£ù Gó™ -3™ ªè£´‚ Gallery gallery = (Gallery)findViewById(R.id.gallery); gallery.setAdapter(new ImageAdapter(this)); gallery.setOnItemClickListener(new onItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // TODO Auto-generated method stub Toast.makeText(GalleryActivity.this,""+ position, Toast.LENGTH_SHORT).show(); }} ); <?xml version="1.0" encoding="utf- 8"?> <resources> <declare-styleable name="HelloGallery"> <attr name="android:galleryItemBackground "/> </declare-styleable> </resources> èŠð†´œ÷¶. <attr> âLªñ¡† Íô‹ v¬ìL¬ù android.gallery ItemBack ground â¡Á °PŠH†´œ«÷£‹. Ü´ˆîî£è ImageAdapter.java â¡ø ç¬ðL¬ù à¼õ£‚è «õ‡´‹. à¼õ£‚èŠ ð´‹«ð£¶ «ðv Ü죊ìK¬ù (Base Adapter) Extend ªêŒò «õ‡´‹. (Gó™-4) Array- J¬ù ªè£‡´ drawable Folder- ™ ެ특 ãŸð´ˆî «õ‡´‹. Ü´ˆîî£è Class Constructor ðò¡ð´ˆîŠð†´œ÷¶. Gó™-2 Gó™-3 ðì‹-3 ðì‹-4
  • 3. package ram.com.gallery; import android.content.Context; import android.content.res.TypedArray; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private Context mContext; private Integer[] mImageIds ={ R.drawable.sample1, R.drawable.sample2, R.drawable.sample3, R.drawable.sample4, R.drawable.sample5, R.drawable.sample6, R.drawable.sample7 }; public ImageAdapter(Context c){ mContext = c; TypedArray attr = mContext.obtainStyledAttributes(R.styleab le.HelloGallery); mGalleryItemBackground = attr.getResourceId(R.styleable.HelloGaller y_android_galleryItemBackground, 0); attr.recycle(); } @Override public int getCount() { // TODO Auto-generated method stub return mImageIds.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return mImageIds[position]; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return mImageIds[position]; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ImageView imageView = new ImageView(mContext); imageView.setImageResource(mImageIds [position]); imageView.setLayoutParams(new Gallery.LayoutParams(150,100)); imageView.setScaleType(ImageView.Scal eType.FIT_XY); imageView.setBackgroundResource(mGall eryItemBackground); return imageView; } } Gó™-4 Þƒ° Þ«ñx Ü죊켂 è£ù Context õ¬óòÁ‚èŠ ð†´œ÷¶. Ü´ˆîî£è style able resource â¡ðî¬ù attr â¡ø çd™´ (Field) Íô‹ °PŠHìŠ ð†´œ÷¶. Constructor- ¡ º®M™ Typed Array -J¬ù ®¬õv e‡´‹ ðò¡ð´ˆîô£‹ â¡ðîŸè£è recycle() ðò¡ð´ˆîŠð† ´œ÷¶. Þ«ñT¬ù «èôK»ì¡ ެ특 ãŸð´ˆ¶õ getCount(),getItem() ñŸÁ‹ getIte mId() ªñˆî†èœ ðò¡ ð´ˆîŠð†´œ÷¶. getview ªñˆî† Íô‹ ContextMember Íô‹ Þ«ñx MÎ à¼õ£‚èŠ ð†´œ÷¶. Þ«ñx MÎMŸ° drawble- L™ àœ÷ ðìƒèÀì¡ Þ¬íŠ¹ ãŸð´ˆîŠð†´œ ÷¶. imageView.setImageResourc e(mImageIds [position]; Þ«ñx MÎM¡ c÷ ñŸÁ‹ ÜèôˆF¬ù Gallery.Layout params Íô‹ °PŠH†´œ «÷£‹.
  • 4. ðì‹-6ðì‹-5 - ªî£ì¼‹ i m a g e V i e w . S e t L a y o u t Params (new Gallery. Layout Params(150,100); Þî¬ù «ð£¡«ø, SetScaleType ñŸÁ‹ SetBack groundResource ðò¡ð´ˆîŠ ð†´œ÷¶. ÜŠO«èê¬ù ªêò™ð´ˆ¶õ ºîL™ Project-Build Project â¡ð î¬ù AO‚ ªêŒò «õ‡´‹. H¬öèœ ã«î‹ Þ¼‰î£™ Þ‰î ªêò™ Íô‹ ÜP‰¶ ªè£œ÷ô£‹. Ü´ˆîî£è «èôK â¡ø Šó£ªü‚†®¬ù «î˜¾ ªêŒ¶ Run As>Android Appli cation â¡Á AO‚ ªêŒò «õ‡´‹. (ðì‹-3) Run As> Android Application â¡ðî¬ù «î˜¾ ªêŒî¾ì¡ ðì‹-4™ àœ÷¶ «ð£¡Á «î£¡Á‹. «î¬õò£ù ⺠«ô†ìK¬ù«ò£ (Emulator) Ü™ô¶ ®¬õC¬ù«ò£ «î˜‰ ªî´ˆ¶ ªè£œ÷ô£‹. «èôK ÜŠO«èê¡ ðì‹-5™ àœ÷¶ «ð£¡Á F¬óJ™ «î£¡Á‹ ðìˆF¬ù ®¬õvªî£´F¬óJ™ªî£† 죙 ðìˆF¡ ⇠F¬óJ™ «î£¡Á‹. (ðì‹-6)