2012-04-11 81 views
0

我正在一個程序中,我想點擊一個按鈕,並在顯示隨機圖像的屏幕中間出現一個彈出窗口。然後在點擊彈出窗口時關閉彈出窗口。彈出一個顯示一個隨機圖像,然後點擊時關閉

我的問題是這樣嗎?如果是的話如何?

+1

是的,這是可能的。爲了獲得進一步的幫助,您需要找到更具體的問題。 – Shaded 2012-04-11 15:15:56

回答

1

是的你不能。爲此,您需要創建一個Custom Alert dialog,使其中的圖像視圖膨脹並在點擊所需對象時調用它。您還需要通過在AlertDialog中添加close button來關閉它來設置一個onlick監聽器。

+0

謝謝!我會給這一槍! – bribrem 2012-04-11 15:43:43

+0

當然。如果它有效,請投票並接受答案以關閉該線程。如果沒有,請繼續詢問。 – 2012-04-11 15:46:57

+0

我現在已經成功了...非常困惑...和一個應用程序崩潰時,我試圖打開它... – bribrem 2012-04-13 05:18:22

0

是的,你可以使用這樣的事情:

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(); 

custom_message_dialog.xml - 可能是這個樣子:

<?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> 

的ClickListener

public void onClick(View v) { 
if(v == closeButton){ 
confirmDeleteDialog.dismiss(); 
}} 
相關問題