2016-04-29 61 views
0

我建立一個自定義對話框彈出與關閉按鈕像這樣的圖片:的Android定製對話框不能填滿整個對話框佈局

result

正如你所看到的對話框沒有安裝對話框佈局和在頂部和右側有這個白色蛀蟲,所以我該如何擺脫白色邊框的東西,並使我的自定義對話框適合?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:gravity="center" 
    android:orientation="vertical" > 

<FrameLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" > 

    <LinearLayout 
     android:id="@+id/linearMain" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="10dp" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:paddingBottom="-50dp" > 
     <ImageView 
      android:id="@+id/imgMain" 
      android:layout_width="300dp" 
      android:layout_height="350dp" 
      android:gravity="center" 
      android:background="@drawable/eairh_dialog" 
      /> 

     <!---add your views here--> 
    </LinearLayout> 
    <ImageView 
     android:id="@+id/imgClose" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|right" 
     android:clickable="true" 
     android:src="@drawable/close_button" /> 
</FrameLayout> 

</LinearLayout> 
+0

刪除保證金的頂部和右邊的.. –

+0

刪除機器人:layout_marginRight =「5DP」 機器人:layout_marginTop =「10dp」從線性佈局 –

回答

1
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 

使用上面的代碼在對話框類進行對話透明

+0

它的工作的感謝 –

0

上的LinearLayout刪除距頂部和右側:

android:layout_marginRight="5dp" 
android:layout_marginTop="10dp" 
+0

它的工作,但收盤圖像現在主要內圖像,我想要像第一張圖片一樣的近距離圖像 –

0

爲了使對話框變大,你可以設置這些參數傳遞給MATCH_PARENT。

int screenWidth = 0, screenHeight = 0 ; 
Display display = thid.getWindowManager().getDefaultDisplay(); 
     screenWidth = display.getWidth(); 
     screenHeight = display.getHeight(); 


     Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_DeviceDefault); 
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     dialog.setContentView(R.layout.cart_empty); 

      WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
     lp.copyFrom(dialog.getWindow().getAttributes()); 
     lp.width = screenWidth; 
     lp.height = screenHeight; 
     dialog.getWindow().setAttributes(lp); 
     dialog.show();