Android 片段内部的线性布局始终在顶部留下空白

Android 片段内部的线性布局始终在顶部留下空白,android,user-interface,android-fragments,layout,fragment,Android,User Interface,Android Fragments,Layout,Fragment,开发人员 我对碎片有问题。我家碎片中的两条直线布局总是在顶部留下无法解释的空白。这会造成问题,因为它会占用其他UI元素的空间,而这些UI元素需要适合该片段。参见图 [编辑]包括布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

开发人员

我对碎片有问题。我家碎片中的两条直线布局总是在顶部留下无法解释的空白。这会造成问题,因为它会占用其他UI元素的空间,而这些UI元素需要适合该片段。参见图

[编辑]包括布局文件

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="10">

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="vertical"
        android:background="@color/black">

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="8"
        android:orientation="vertical"
        android:background="@color/teal_200">
    </LinearLayout>

尝试将
XML
文件中的主题从您的文件转换为
AppCompat.Light.NoActionBar

或者您可以尝试在
style.xml
文件中手动执行此操作:



在这个特定的案例中,它是android:paddingTop=“?attr/actionBarSize
但是,大多数情况下,你需要以前的解决方案来解决这个问题,使用
ActionBar
。我会像我所有的帖子一样更新帖子。

如果你能提供你的布局文件,那就太好了。你能提供活动的布局吗?布局中有一段带有底部导航的代码。删除它后,所有内容都返回到normal.android:paddingTop=“?attr/actionBarSize”好的。很高兴您修复了它!:)我将此添加到我的答案中,它可以帮助其他人。快乐编码!:)
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">