Reputation: 961
I am coding image gridview in android and I would like to question you how to show Large image when user click on small image in gridview and how can I make gridview able to scrolling by swipe because my gallery has a lot of images.
Here is my code:
public class myalbum extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myalbum);
GridView gridView = (GridView) findViewById(R.id.gridview);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new GridView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
//Here I want to see Large Image???? How can i do?????
Toast.makeText(myalbum.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
HashMap<Integer, Matrix> mImageTransforms = new HashMap<Integer,Matrix>();
Matrix mIdentityMatrix = new Matrix();
//---returns an ImageView view---
// create a new ImageView for each item referenced by the Adapter
public View getView(int 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(88, 88));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(2, 2, 2, 2);
} else {
imageView = (ImageView) convertView;
}
Matrix m = mImageTransforms.get(position);
if ( null == m ) {
m = mIdentityMatrix;
}
imageView.setImageMatrix(m);
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
void setImageRotation(int position, int degrees) {
Matrix m = mImageTransforms.remove(position);
if ( degrees != 0 ) {
if ( null == m ) m = new Matrix();
m.setRotate(degrees);
mImageTransforms.put(position, m);
}
notifyDataSetChanged();
}
private Integer[] mThumbIds = {
R.drawable.p1, R.drawable.p2,
R.drawable.p1, R.drawable.p2,
R.drawable.p1, R.drawable.p2,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4
};
}
}
Best Regards, Virak
Upvotes: 1
Views: 882
Reputation: 2628
Actually i can't get where you actually want to display image. By the way you need to add your grid view in FrameLayout so, after that you can create on layout programmatically(with background color transparent) add imageView to it in same way and add that layout to your frameLayout and on image click you can set its visibility to visible so it displays image on top of your grid view as you simply view images on FB and provide close button which sets the visibility of that layout to Gone.
Hope this helps you. let me know if any problem..
Upvotes: 1