实现与双指缩放图库 [英] Implementing a Gallery with pinch zoom
问题描述
我有一个图像画廊,我想就可以启用双指缩放。另外,他们的工作就好了。问题是,我不能为我的生活结合他们两个人在一起!我试图在ImageZoomView绑定在ImageAdapter,都无济于事。我应该尝试这样做,当用户点击了图片?没有人有任何其他的想法? 这是code在ImageAdapter.class返回画廊元素:
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;
}
这是我如何处理它MainActivity.class:
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();
}
});
正如你所看到的,我试过的东西,但我的应用程序总是崩溃。 :(任何帮助将AP preciated。
As you can see, I tried something, but my app always crashes. :( Any help here would be appreciated.
推荐答案
您应该创建 ImageZoomView
在 getView
法,假设ImageZoomView是你自己的子类ImageView的小部件的部件。
You should create the ImageZoomView
in the getView
method, assuming the ImageZoomView is a widget of your own subclassing the ImageView widget.
这篇关于实现与双指缩放图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!