2014-12-03 20 views
0

我想用ImageView和一個按鈕創建一個對話框。我添加和運行的ImageView,但是我無法在對話框中添加的按鈕,該按鈕不顯示。 我該怎麼辦?帶有Button和ImageView的對話框?

這裏我怎麼試。

XML

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"   
    > 

    <ImageView 
     android:id="@+id/ivCustomDialog" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="0dp" 
     android:scaleType="centerCrop"     
     /> 

    <Button 
     android:id="@+id/btnProsseguir" 
     android:layout_width="100px" 
     android:layout_height="wrap_content" 
     android:background="@drawable/resp_prosseguir" 
     android:layout_marginTop="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_below="@+id/ivCustomDialog" 
     /> 

</RelativeLayout> 

//活動

private void showDialog(final RespostaPergunta resposta){     
      final Dialog dialog = new Dialog(getView().getContext()); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
      dialog.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);       
      dialog.setContentView(R.layout.custom_dialog); 
      dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
      ImageView ivCustomDialog = (ImageView) dialog.findViewById(R.id.ivCustomDialog); 

      Button dialogButton = (Button) dialog.findViewById(R.id.btnProsseguir); 
      dialogButton.setOnClickListener(new OnClickListener() {    
       @Override 
       public void onClick(View v) { 
        FragmentTransaction ft; 
        Fragment frag = new InicioFrag(); 
        if(resposta.getValor() == 1){ 
         frag = new SalaInternaFrag(); 
         ft = getFragmentManager().beginTransaction(); 
         ft.replace(R.id.fl, frag); 
         ft.addToBackStack("back"); 
         ft.commit(); 
        }else{ 
         frag = new InicioFrag(); 
         ft = getFragmentManager().beginTransaction(); 
         ft.replace(R.id.fl, frag); 
         ft.addToBackStack("back"); 
         ft.commit();       
        }      
        dialog.dismiss();     
       } 
      });   

      if(resposta.getValor() == 1){ 
       ivCustomDialog.setImageResource(R.drawable.resp_correto); 
      }else{ 
       ivCustomDialog.setImageResource(R.drawable.resp_errado); 
      } 

      dialog.show(); 

     } 
+0

將'RelativeLayout'的'height'改爲'wrap_content' – 2014-12-03 20:34:46

+0

我改變了,但不行! – FernandoPaiva 2014-12-03 20:41:51

+0

該按鈕沒有顯示?或按鈕點擊不起作用? – Rami 2014-12-03 20:52:46

回答

0

我解決了這個問題。

我做到了。

<RelativeLayout  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"   
    xmlns:android="http://schemas.android.com/apk/res/android"> 


     <ImageView 
      android:id="@+id/ivCustomDialog" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="0dp" 
      android:scaleType="centerCrop"     
      /> 


     <Button 
      android:id="@+id/btnProsseguir" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/resp_prosseguir"      
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true"   
      /> 


</RelativeLayout> 
0

也沒準按鈕添加到對話,但可以看到它,因爲所有的空間由圖像佔用,嘗試將圖像視圖和按鈕添加到滾動視圖(垂直) 類似這樣的東西

<ScrollView 
.. 
.. > 
    <LinearLayout ...> 
     <ImageView .../> 
     <Button .... /> 
    </LinearLayout> 
</ScrollView> 

運行,如果你能看到按鈕向下滾動以及你只需要改變圖像的寬度和高度