Home >> Miscellaneous
Android's Gallery element used in this Example to show multiple
Image views in a slider/spinner mode. And displaying selected item/image
on a different
In this example I am going to try showing up set of ImageViews by
adding these along with Gallery View element/API from Android's API.
For this example I have created following images:
GalleryImagesProject.java
package com.techienjoy.example.gallery;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class GalleryImagesProject extends Activity {
Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
context = getApplicationContext();
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setSpacing(1);
gallery.setAdapter(new ExampleAdapter());
gallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2,
long arg3) {
ImageView fullView = (ImageView) findViewById(R.id.fullview);
fullView.setImageDrawable(((ImageView)v).getDrawable());
}
});
}
private class ExampleAdapter extends BaseAdapter {
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
ImageView imView = null;
if(position == 0) {
imView = new ImageView(context);
imView.setImageResource(R.drawable.camera1);
}
if(position == 1) {
imView = new ImageView(context);
imView.setImageResource(R.drawable.camera2);
}
if(position == 2) {
imView = new ImageView(context);
imView.setImageResource(R.drawable.camera3);
}
if(position == 3) {
imView = new ImageView(context);
imView.setImageResource(R.drawable.camera4);
}
return imView;
}
@Override
public int getCount() {
return 4;
}
@Override
public Object getItem(int position) {
return position;
}
}
}
|
Above source code has many methods left unimplementated as these methods
are not going to help directly in achiving objective of this example. I
have tried to override selective few methos such as getView that returns
appropriate view based on the position argument parameter value.
getCount method shows count value for number of images to be used for
showing on spinner widget.
Android Manifest file for this example, that is automatically generated:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.techienjoy.example.gallery"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".GalleryImagesProject"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
>
<Gallery android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/gallery1"
android:layout_gravity="center"
>
</Gallery>
<ImageView android:id="@+id/fullview" android:layout_width="60dip"
android:layout_height="60dip"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
/>
</LinearLayout>
|
After building up these files along with image files in appropriate folders
such as four images are copied into folder "drawable" under 'res' folder,
we have the following screen shot as shown in Android Emulator.

I have used Android version 2.1-update1 SDK for this example, along with
Eclipse as Android Application Editor/IDE, Java Platform 1.6.

One can still enhance this example to use for viewing different photos,
those are present in some folder.
If anything missed out , please let me know at
techienjoy at yahoo . com
|
|
|
|
|
|
|
|
| Android ListView Example : |
Example on Android ListView and
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
|
|
|
|
|
| Android ListView Example : |
Example on Android List View
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
| Android Sensors Example : |
Example on Android Sensors Listed and
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
| Android Tab View Example : |
Example on Android Tab View
explained with a very simple scenario
and appropriate screens captured and shown.
|
|
|
|
| Android Examples : |
List of ANDROid examples
with source code and output
screens captured and shown.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Android ListView Example : |
Example on Android ListView
explained with a very simple scenario
whereby showing folder and files with
structure and appropriate screens
captured and shown.
|
|
|
|
|
| Google GWT Example : |
Example using GWT and some design patterns and various
ways of implementing this example.
|
|
|
|
|
|
|
|
|
| Android Gallery Example : |
Example on Android Gallery View
explained with a very simple scenario
and appropriate screens captured and shown.
|
|
|
|
|
|
|
|