Implementing a Gallery with pinch zoom
Frage
I have a gallery of images and I'm trying to enable pinch zoom on it. Separately, they work just fine. The problem is, I can't for the life of me bind the two of them together! I tried to bind the ImageZoomView in the ImageAdapter, to no avail. Should I try doing it when the user clicks the image? Does anyone have any other ideas? This is the code in ImageAdapter.class that returns the gallery elements:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(),mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(300, 450));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
i.setImageBitmap(bitmap);
return i;
}
And this is how I handle it in MainActivity.class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
Log.i("blah","e ok");
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// mBitmap = ImageAdapter.mImageIds[position];
// mZoomView = (ImageZoomView)findViewById(R.id.zoomview);
// mZoomView.setZoomState(mZoomControl.getZoomState());
// mZoomView.setImage(mBitmap);
// Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
As you can see, I tried something, but my app always crashes. :( Any help here would be appreciated.
Keine korrekte Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow