简体   繁体   English

在Android中显示图像预览

[英]Showing an image preview in Android

I want to show the images that are on the phone to the user. 我想向用户显示手机上的图像。 but I want to show the user a preview of the images. 但我想向用户显示图像的预览。

在此处输入图片说明

And when the user touches an image, I want to show a path of the image. 当用户触摸图像时,我想显示图像的路径。

I have a button in my layout. 我的布局中有一个按钮。 how can show the images, when click the button. 单击按钮时如何显示图像。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/back_default">

    <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_pickimage" android:id="@+id/btn_pickimage"></Button>

</LinearLayout>

I think you should look at Android Gallery and Android GridView 我认为您应该看看Android GalleryAndroid GridView

When you click the button just put Intent to direct to GridView. 当您单击按钮时,只需将Intent定向到GridView。

And about clicking the image to show its path is another different thing. 关于单击图像以显示其路径是另一回事。 You could build a custom layout or Toast or whatever to meet your need to show the path. 您可以构建自定义布局或Toast或满足显示路径所需的任何内容。 Put onClick listener on the Image to do so. 为此,请在图片上放置onClick侦听器。

As I understood you want to show the thumbnail image first(as shown in your link) and by clicking any of image should enlarge that particular image in a different view, 据我了解,您想先显示缩略图(如您的链接所示),然后通过单击任意图像应在另一视图中放大该特定图像,

Then simple approach.. 然后简单的方法..

1.Make two separate activity for preview and large image
2. Store all your image in a array(If you have diff images for preview and large image then place accordingly).
3. set id for each imageview (In preview mode)
4. send id of selected imageview to next activity using putextra
5. Use id to access the array

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

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