简体   繁体   English

Android Gallery onItemClick显示大图

[英]Android gallery onItemClick show larger image

I've just finished copying the android walkthrough for the gallery (http://developer.android.com/resources/tutorials/views/hello-gallery.html) and was wondering how I would go about having the thumbnail photo scale into a larger one within the onClickItem method. 我刚刚完成了画廊的android演练的复制(http://developer.android.com/resources/tutorials/views/hello-gallery.html),并且想知道如何将缩略图比例缩放到onClickItem方法中较大的一个。

        public void onItemClick(AdapterView parent, View v, int position, long id) {
            Toast.makeText(ProjectPreview.this, "" + position, Toast.LENGTH_SHORT).show();
        }

Currently it just shows the position as depicted in the Toast. 目前,它仅显示吐司中描述的位置。 Could someone point me in the right direction or show me a simple way? 有人可以指出我正确的方向还是向我展示一个简单的方法?

Thanks in advance. 提前致谢。

EDIT: Added this method and called it in the onItemClick sending it the position. 编辑:添加了此方法,并在onItemClick中调用它,将其发送给该位置。 And it works. 而且有效。

    public void showLarger(int position){
        ImageView image = (ImageView) findViewById(R.id.iv1);
        image.setLayoutParams(new Gallery.LayoutParams(200, 100));
        image.setScaleType(ImageView.ScaleType.FIT_XY);
        image.setImageResource(mImageIds[position]);
    }

使用具有包含imageview的布局的Dialog,并设置其源案例的位置和所需的大小。

I would use a Dialog. 我会使用一个对话框。 You can create a new activity and have an ImageView in its layout, and disguise that Activity as a Dialog. 您可以创建一个新的活动,并在其布局中具有ImageView,然后将该活动伪装为对话框。 See this question for how to do all that: Android Image Dialog/Popup 有关如何执行所有操作的信息,请参见以下问题: Android图像对话框/弹出窗口

As mentioned above, you can use a Dialog to display the larger image or you can just fire an intent that would start a regular Activity(You will have to add the dialog Theme to your Activity if you do it as described as above). 如上所述,您可以使用对话框显示较大的图像,也可以仅触发将启动常规活动的意图(如果按照上述说明进行操作,则必须将对话框主题添加到活动中)。

You'd have to do something like call v.getItemID(position) and store that in a String, then pass that into your next Activity. 您必须执行类似调用v.getItemID(position)的操作并将其存储在String中,然后将其传递到下一个Activity中。

Either way, you'll have to pass in some data to your Activty that will host the ImageView, and then use that data(path, uri, etc) to inflate your larger ImageView. 无论哪种方式,您都必须将一些数据传递到将托管ImageView的Activty中,然后使用该数据(路径,uri等)来填充较大的ImageView。 Just don't forget to add the theme to your manifest if you want use the Dialog route. 如果您想使用Dialog路由,请不要忘记将主题添加到清单中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM