【问题标题】:Android custom dialog not fill the entire dialog layoutAndroid自定义对话框没有填满整个对话框布局
【发布时间】:2016-04-29 10:18:37
【问题描述】:

我构建了一个自定义对话框来弹出带有关闭按钮的图像,如下所示:

如您所见,对话框不适合对话框布局,顶部和右侧都有这个白色的蛀虫,那么我怎样才能摆脱白色边框的东西并让我的自定义对话框适合?

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

【问题讨论】:

  • 去掉上下边距..
  • 从线性布局中移除 android:layout_marginRight="5dp" android:layout_marginTop="10dp"

标签: java android xml layout dialog


【解决方案1】:
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

在 Dialog 类中使用上述代码来制作 Dialog TransParent

【讨论】:

    【解决方案2】:

    删除LinearLayout上的顶部和右侧边距:

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

    【讨论】:

    • 它正在工作,但关闭图像现在在主图像内,我想要关闭图像就像第一张图片一样
    【解决方案3】:

    要使对话框更大,您可以将这些参数设置为 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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多