Android的/ Java的 - 在的弹出窗口按钮被点击后,显示图像 [英] Display image in popout window after button is clicked -- Android/Java

查看:351
本文介绍了Android的/ Java的 - 在的弹出窗口按钮被点击后,显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个解决这个问题的几个小时在网上和我似乎无法找到问题的解答。
我写了使用相机模拟器在Eclipse中拍照,并将其保存到SD卡(路径是使用一个名为文件字符串存储)的Andr​​oid应用程序。我想这样做是一种弹出窗口pferably显示图像,$ P $,另一个按钮将其关闭并返回到应用程序。我想我会需要创建另一个类来做到这一点,但我不知道所有的参与。请问我要创建另一个XML文件进行布局?我怎么能访问该文件并显示它?我希望如果我使用另一个类,我将使用ImageView的,但除此之外,我不知道该怎么办。
没有太多code,我可以真正提供能够帮助,比点击按钮时被调用的方法等。在code的这部分工作得很好,而且它只是看起来像这样的方法:

 公共无效viewPhoto(文件){}

正如你所看到的,我有方法中算不了什么,这就是为什么我张贴在这里。
我一直在试图弄清楚这一点了好几个小时,所以我将不胜AP preciate任何想法,你的乡亲可能。

编辑:更多资讯

许多我发现的建议要求在图像被存储在项目中的SRC文件夹。然而,这张照片将采取所有在同一程序中使用,所以我必须要能够单独使用它的文件路径来访问它。我不能只说​​出了XML的位置。我创建了一个对话的对象我现有的code之内,但我不知道这是否会工作。我打算使用该对话框应该能够从存储前面提到的字符串中指定的路径访问的照片。

我已经提到了这一主题的第一个答案: Android的图像对话框/弹出
但你可以看到它需要的图像是在src文件夹,并在XML中指定。

第二编辑:

下面是code我现在有,既为XML和Java。但首先,我想提一提,我有两个XML文件 - 一个叫activity_main.xml中负责处理所有最初的按钮,菜单等;二是只为我的照片(称为photo_viewer.xml),它仅包含的ImageView

photo_viewer.xml:

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID /图片查看器
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT>    < ImageView的
        机器人:ID =@ + ID / ImageView的
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:contentDescription =@字符串/ viewImage/>< / RelativeLayout的>

Java的方法生成的图像:

 公共无效viewPhoto(字符串文件){
    ImageView的ImageView的=新ImageView的(getApplicationContext());
    的LayoutParams LP =新的LayoutParams(LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT);
    位图图像= BitmapFactory.de codeFILE(文件);
    imageView.setImageBitmap(图片);
    RelativeLayout的RL =(RelativeLayout的)findViewById(R.id.pictureViewer);
    rl.addView(ImageView的,LP);
}


解决方案

您需要创建一个类将扩大对话类。

请参阅本如何创建自己的对话框。

如何在Android中创建一个自定义对话框<? / A>

然后用于显示图像只需调用DialogObj.show()来显示对话框。

I've been searching the internet for a solution to this problem for several hours now and I can't seem to find an answer that works. I have written an android app that uses the camera emulator in Eclipse to take a photo and save it to the sd card (path is stored using a String called "file"). What I would like to do is display the image, preferably in a sort of pop-out window, with another button that closes it and returns to the app. I expect I'll need to create another class to do this, but I am not sure all that is involved. Will I have to create another XML file to do the layout? How could I access the file and display it? I expect I'll use ImageView if I am to use another class, but other than that I'm not sure what to do. There's not much code I can really provide that would help, other than the method which is called when the button is clicked. This part of the code works just fine, and it's simply a method that looks like this:

public void viewPhoto(file){ }

As you can see, I have nothing inside the method yet, that is why I am posting here. I have been trying to figure this out for several hours, so I would greatly appreciate any ideas you folks might have.

EDIT: MORE INFO

Many of the suggestions I have found require the image to be stored in the "src" folder of the project. However, this photo will be taken and used all within the same program, so I'll have to be able to access it using its file path alone. I can't just state its location in the XML. I created a Dialog object within my existing code, but I'm not sure if this will work. The dialog I plan to use should be able to access the photo from the specified path that is stored in the string mentioned before.

I have been referring to the first answer in this thread: Android Image Dialog/Popup but as you can see it requires the image to be in the src folder and specified in the XML.

SECOND EDIT:

Here is the code I currently have, both for the XML and the Java. But first I want to mention that I have two XML files--one called activity_main.xml which handles all the initial buttons, menu, etc. The second one is only for my photo (called photo_viewer.xml) and it only contains the ImageView.

photo_viewer.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pictureViewer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/viewImage" />

</RelativeLayout>

Java method to generate image:

public void viewPhoto(String file){ 
    ImageView imageView = new ImageView(getApplicationContext());
    LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT);
    Bitmap image = BitmapFactory.decodeFile(file);
    imageView.setImageBitmap(image);
    RelativeLayout rl = (RelativeLayout)findViewById(R.id.pictureViewer);
    rl.addView(imageView, lp);
}

解决方案

you need to create a class which would extend Dialog Class.

refer this how you can create your own dialog.

How to create a Custom Dialog box in android?

then for showing image just call DialogObj.show() to show dialog.

这篇关于Android的/ Java的 - 在的弹出窗口按钮被点击后,显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆