简体   繁体   English

自定义对话框用白色背景填充整个屏幕

[英]Custom dialog fills all the screen with white background

I'm trying to do a custom dialog, but everytime I run the app, it fills the screen with a white background, like that: image我试图做一个自定义对话框,但每次我运行应用程序,它填补了屏幕在白色背景,这样的:图片

See my XML code (I already tried without this LinearLayout, only with ConstraintLayout, changing the background color, but nothing works.):查看我的 XML 代码(我已经尝试过不使用此 LinearLayout,仅使用 ConstraintLayout,更改背景颜色,但没有任何效果。):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="center"
android:padding="20dp">

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/shadow"
        android:layout_width="wrap_content"
        android:layout_height="223dp"
        android:layout_marginTop="89pt"
        android:src="@drawable/action_box_shadow_box"
        app:layout_constraintBottom_toTopOf="@+id/box"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <ImageView
        android:id="@+id/triangle"
        android:layout_width="176dp"
        android:layout_height="236dp"
        android:gravity="center"
        android:src="@drawable/action_box_triangle"
        app:layout_constraintBottom_toBottomOf="@+id/box"
        app:layout_constraintEnd_toEndOf="@+id/box"
        app:layout_constraintHorizontal_bias="0.33"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.344" />

    <ImageView
        android:id="@+id/box"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/action_box_box"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/action_bar"
        android:layout_width="260dp"
        android:layout_height="55dp"
        android:src="@drawable/action_box_bar"
        app:layout_constraintBottom_toBottomOf="@+id/box"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.496"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/box"
        app:layout_constraintVertical_bias="0.811" />

    <TextView
        android:id="@+id/action_text"
        android:layout_width="253dp"
        android:layout_height="102dp"
        app:layout_constraintBottom_toBottomOf="@+id/box"
        app:layout_constraintEnd_toEndOf="@+id/shadow"
        app:layout_constraintStart_toStartOf="@+id/shadow"
        app:layout_constraintTop_toTopOf="@+id/shadow"
        app:layout_constraintVertical_bias="0.286" />

</androidx.constraintlayout.widget.ConstraintLayout>

I think it's a problem with the constraints, but I have no idea of how to solve it.我认为这是约束的问题,但我不知道如何解决它。

You are using fixed height for your views.您正在为您的视图使用固定高度。 The fixed heights are rather large as well.固定高度也相当大。 Your base root layout has wrap_content for height, so the overall size of the layout or "Dialog" is going to be huge.您的基本根布局具有wrap_content高度,因此布局或“对话框”的整体大小将是巨大的。 try using wrap_content for the heights of your nested views and see how it looks.尝试将wrap_content用于嵌套视图的高度并查看它的外观。

Using constraint layout with both top and bottom constrained for a view, you can also use 0dp for height.对视图使用顶部和底部约束的约束布局,您还可以使用0dp表示高度。 Check it out and see how it changes the look.检查一下,看看它如何改变外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM