Android 窗口比它大';这是唯一的布局。如何使其包装内容?

Android 窗口比它大';这是唯一的布局。如何使其包装内容?,android,layout,height,android-constraintlayout,Android,Layout,Height,Android Constraintlayout,我在Android应用程序中有一个窗口大小不正确。目标是让窗口包装它的内容(文本视图< /Cord>-s和两个代码>按钮 -s),因此它是屏幕中间的窗口,但它的高度仍然是整个屏幕,尽管我的每一次尝试。 图像: 从代码中可以看到,蓝色是包含布局的背景,黑色是主布局的背景(用于调试) 代码/布局: 活动的XML格式: 包含的布局的XML: 窗口样式的XML: 真的 @android:彩色/黑色 @空的 真的 真的 假的 研究:研究这个问题被证明是非常困难的,因为每个搜索结果要么是关于Re

我在Android应用程序中有一个窗口大小不正确。目标是让窗口包装它的内容(<代码>文本视图< /Cord>-s和两个代码>按钮<代码> -s),因此它是屏幕中间的窗口,但它的高度仍然是整个屏幕,尽管我的每一次尝试。

图像:
从代码中可以看到,蓝色是包含布局的背景,黑色是主布局的背景(用于调试)

代码/布局:
活动的XML格式:


包含的布局的XML:


窗口样式的XML:


真的
@android:彩色/黑色
@空的
真的
真的
假的
研究:研究这个问题被证明是非常困难的,因为每个搜索结果要么是关于
RelativeLayout
-s的问题,要么是关于内容大于窗口的情况,而不是相反。所以我的研究主要是在谷歌和这里没有找到任何东西后,随机修改布局的高度设置(和样式),所以大多数看起来合乎逻辑的组合都会被尝试和测试

平台:安卓6.0.1,API 23

编辑:我知道浮动窗口是一种不受欢迎的显示内容的方式,但我不负责设计,只负责实现

EDIT2:更接近找到问题所在-包含的布局是原因,解决方案是在浮动窗口中复制该布局的内容,而不是简单地包含整个布局。无论是因为包含的事实还是包含的布局的细节都不清楚。

试试这个

 Window window = dialog.getWindow();
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    window.setGravity(Gravity.CENTER);
试试这个

 Window window = dialog.getWindow();
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    window.setGravity(Gravity.CENTER);

试试这个

<style name="Transparent" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowIsTranslucent">true</item>
            <item name="android:windowBackground">@color/black_20</item>
            <item name="android:windowContentOverlay">@null</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowIsFloating">false</item>
            <item name="android:backgroundDimEnabled">true</item>
        </style>



<RelativeLayout 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="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="@dimen/_100dp"
    android:background="@android:color/white"
    tools:ignore="MissingPrefix">

    // place components here 


</RelativeLayout>

真的
@颜色/黑色\u 20
@空的
真的
假的
真的
//在此放置组件

试试这个

<style name="Transparent" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowIsTranslucent">true</item>
            <item name="android:windowBackground">@color/black_20</item>
            <item name="android:windowContentOverlay">@null</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowIsFloating">false</item>
            <item name="android:backgroundDimEnabled">true</item>
        </style>



<RelativeLayout 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="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="@dimen/_100dp"
    android:background="@android:color/white"
    tools:ignore="MissingPrefix">

    // place components here 


</RelativeLayout>

真的
@颜色/黑色\u 20
@空的
真的
假的
真的
//在此放置组件
<style name="Transparent" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowIsTranslucent">true</item>
            <item name="android:windowBackground">@color/black_20</item>
            <item name="android:windowContentOverlay">@null</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowIsFloating">false</item>
            <item name="android:backgroundDimEnabled">true</item>
        </style>



<RelativeLayout 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="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="@dimen/_100dp"
    android:background="@android:color/white"
    tools:ignore="MissingPrefix">

    // place components here 


</RelativeLayout>