gallery slider

Quickly share your Android Code Snippets here...

gallery slider

Postby weldrian » Fri Dec 19, 2008 8:11 am

i have made some modification on the image gallery. any one interested , can have a look.
or give me some advise.
now i m achieved
1.how to load pic on emulator.
2. Make a slider for choosing the next pic.


so next step i will be looking for a zoom in and zoom out...
let me know if u have any idea.
weldrian
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue Dec 09, 2008 1:30 am

Top

forgot to put my code.

Postby weldrian » Fri Dec 19, 2008 8:14 am

here is the code:




public class Gallery1 extends Activity {


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_1);

// Reference the Gallery view
Gallery g = (Gallery) findViewById(R.id.gallery);
// Set the adapter to our custom adapter (below)
g.setAdapter(new ImageAdapter(this));

// Set a item click listener, and just Toast the clicked position
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show();
}
});

// We also want to show context menu for longpressed items in the gallery
registerForContextMenu(g);
}




@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show();
return true;
}

public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;

public ImageAdapter(Context c) {
mContext = c;
// See res/values/attrs.xml for the <declare-styleable> that defines
// Gallery1.
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}

public int getCount() {
return mImageIds.length;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);

i.setImageResource(mImageIds[position]);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(300, 400));

// The preferred Gallery item background
i.setBackgroundResource(mGalleryItemBackground);

return i;
}

private Context mContext;

private Integer[] mImageIds = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
};
}

}
weldrian
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue Dec 09, 2008 1:30 am

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests