我在android中编码图像gridview,我想问你如何在用户单击gridview中的小图像时显示大图像以及如何使gridview能够通过滑动滚动,因为我的画廊有很多图像。
这是我的代码:
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
};
}
}
最好的问候, 维拉克