Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 制作一个显示随机图像的弹出窗口,然后在单击时关闭 我正在设计一个程序,我想点击一个按钮,在屏幕中间出现一个弹出窗口,显示一个随机图像。然后单击弹出窗口,关闭弹出窗口_Android_Eclipse_Image_Button_Popup - Fatal编程技术网

Android 制作一个显示随机图像的弹出窗口,然后在单击时关闭 我正在设计一个程序,我想点击一个按钮,在屏幕中间出现一个弹出窗口,显示一个随机图像。然后单击弹出窗口,关闭弹出窗口

Android 制作一个显示随机图像的弹出窗口,然后在单击时关闭 我正在设计一个程序,我想点击一个按钮,在屏幕中间出现一个弹出窗口,显示一个随机图像。然后单击弹出窗口,关闭弹出窗口,android,eclipse,image,button,popup,Android,Eclipse,Image,Button,Popup,我的问题是这可能吗?如果是,怎么办?是的,你不能。为此,您需要创建一个用于膨胀布局(其中包含imageview)的视图,并在单击所需对象时调用它。此外,您还需要通过向AlertDialog中添加一个来设置一个onlick侦听器以关闭它。是的,您可以使用以下方法: Dialog confirmDeleteDialog = new Dialog(this); confirmDeleteDialog.setContentView(R.layout.custom_message_dialog); //T

我的问题是这可能吗?如果是,怎么办?

是的,你不能。为此,您需要创建一个用于膨胀布局(其中包含imageview)的视图,并在单击所需对象时调用它。此外,您还需要通过向AlertDialog中添加一个来设置一个onlick侦听器以关闭它。

是的,您可以使用以下方法:

Dialog confirmDeleteDialog = new Dialog(this);
confirmDeleteDialog.setContentView(R.layout.custom_message_dialog);
//This allows dialog to be closed with back button
confirmDeleteDialog.setCancelable(true);
//DisplayMetrics will get the screen dimensions and allow you to 
//declare a center point
DiaplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenHeight = displaymetrics.heightPixels; //Divide by 2 to get mid
int screenWidth = displaymetrics.widthPixels; //Divide by 2 to get mid

Button closeButton = (Button) confirmDeleteDialog.findViewById(R.id.close_button);
closeButton.setOnClickListener(this);
confirmDeleteDialog.show();
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<Button
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"/>

</RelativeLayout>
custom_message_dialog.xml-可能如下所示:

Dialog confirmDeleteDialog = new Dialog(this);
confirmDeleteDialog.setContentView(R.layout.custom_message_dialog);
//This allows dialog to be closed with back button
confirmDeleteDialog.setCancelable(true);
//DisplayMetrics will get the screen dimensions and allow you to 
//declare a center point
DiaplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenHeight = displaymetrics.heightPixels; //Divide by 2 to get mid
int screenWidth = displaymetrics.widthPixels; //Divide by 2 to get mid

Button closeButton = (Button) confirmDeleteDialog.findViewById(R.id.close_button);
closeButton.setOnClickListener(this);
confirmDeleteDialog.show();
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<Button
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"/>

</RelativeLayout>

是的,这是可能的。要获得进一步帮助,您需要找到一个更具体的问题。当然。如果有效,请投票并接受答案以关闭线程。如果没有,继续问。我现在已经成功地。。。非常困惑。。。当我试图打开一个应用程序时,它会崩溃…你能把崩溃的日志放在这里吗?