Java 我如何摆脱Android应用程序顶部出现的额外间距?

Java 我如何摆脱Android应用程序顶部出现的额外间距?,java,android,xml,android-layout,Java,Android,Xml,Android Layout,我正在为我的一个大学班级建立一个Android应用程序的主页。我的小组正在使用Android Studio。我有我以前的布局,但我在上面有一个随机的额外空间,上面写着欢迎 我不知道如何消除顶部的随机间距,它会将我的其余对象向下推。报告列表会消失在导航栏下面 这是我的fragment_home.xml 这是我的HomeFragment.java 包com.example.telemedicine.ui.home; 导入android.app.Activity; 导入android.os.Bundl

我正在为我的一个大学班级建立一个Android应用程序的主页。我的小组正在使用Android Studio。我有我以前的布局,但我在上面有一个随机的额外空间,上面写着欢迎

我不知道如何消除顶部的随机间距,它会将我的其余对象向下推。报告列表会消失在导航栏下面

这是我的fragment_home.xml

这是我的HomeFragment.java

包com.example.telemedicine.ui.home; 导入android.app.Activity; 导入android.os.Bundle; 导入android.view.LayoutInflater; 导入android.view.view; 导入android.view.ViewGroup; 导入android.widget.TextView; 导入androidx.annotation.Nullable; 导入androidx.annotation.NonNull; 导入androidx.fragment.app.fragment; 导入androidx.lifecycle.Observer; 导入androidx.lifecycle.ViewModelProviders; 导入androidx.recyclerview.widget.LinearLayoutManager; 导入androidx.recyclerview.widget.recyclerview; 导入com.example.telemedicine.R; 导入com.example.telemedicine.ui.utilities.RecyclerItem; 公共类HomeFragment扩展了片段{ 私有HomeViewModel HomeViewModel; 私人RecyclerView RecyclerView应用程序、RecyclerView聊天、RecyclerView报告; 私有回收视图。适配器mAdapter_appt、mAdapter_chat、mAdapter_report; private RecyclerView.LayoutManager LayoutManager应用程序、LayoutManager聊天、LayoutManager报告; 私有字符串[]apptData={物理-9/29@10:00am,接种-10/4@1:30pm,检查-10/19@9:00am}; 私有字符串[]chatData={Jane Smith博士、Hayden Lee博士、Michael Dean博士}; 私有字符串[]reportData={血液工作9/10,疫苗接种摘要9/1,物理8/23}; //Activity=ActivitygetContext; 公众观点onCreateView@NonNull充气机, 视图组容器,捆绑包savedInstanceState{ homeViewModel= ViewModelProviders.of this.getHomeViewModel.class; 视图根=充气机.充气机.layout.fragment_home,container,false; final TextView TextView=root.findviewbydr.id.editText; homeViewModel.getText.observethis,新的观察者{ @凌驾 公共空间onChanged@Nullable串{ textView.setTexts; } }; recyclerView_appt=RecyclerViewroot.findViewByIdR.id.recycler_appts; layoutManager_appt=新建LinearLayoutManager this.getActivity; recyclerView_appt.setLayoutManagerlayoutManager_appt; mAdapter_appt=新的回收商应用数据; recyclerView_appt.SetAdapterAdapter_appt; recyclerView\u chat=RecyclerViewroot.findViewByIdR.id.recycler\u chats; layoutManager_chat=新建LinearLayoutManager this.getActivity; recyclerView_chat.setLayoutManagerlayoutManager_chat; mAdapter_chat=新的RecyclerItemchatData; recyclerView_chat.setAdapterAdapter_chat; recyclerView_报告=RecyclerViewroot.findViewByIdR.id.recycler_报告; layoutManager_report=新建LinearLayoutManager this.getActivity; recyclerView_report.setLayoutManagerlayoutManager_report; mAdapter_报告=新的RecyclerItemreportData; recyclerView_report.SetAdapterAdapter_report; 返回根; } } 这是我的HomeViewModel.java

包com.example.telemedicine.ui.home; 导入androidx.lifecycle.LiveData; 导入androidx.lifecycle.MutableLiveData; 导入androidx.lifecycle.ViewModel; 公共类HomeViewModel扩展了ViewModel{ 私有可变livedata多行文字; 公共HomeViewModel{ mText=新的可变LiveData; } 公共LiveData getText{ 返回多行文字; } } 还有我的activity_main.xml

我不知道还应该包括哪些文件,但希望问题出在这四个文件中。我尝试了很多方法来消除这个间隔,但我不知道如何消除它


提前谢谢

在activity\u main.xml中,将“fragment”nav\u host\u fragment layout\u width和layout\u height更改为0dp。这是使用约束的正确形式

 <fragment
    android:id="@+id/nav_host_fragment"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:defaultNavHost="true"
    app:layout_constraintBottom_toTopOf="@id/nav_view"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:navGraph="@navigation/mobile_navigation" />

在activity_main.xml中,将“fragment”导航主机片段布局宽度和布局高度更改为0dp。这是使用约束的正确形式

 <fragment
    android:id="@+id/nav_host_fragment"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:defaultNavHost="true"
    app:layout_constraintBottom_toTopOf="@id/nav_view"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:navGraph="@navigation/mobile_navigation" />

在activity\u main.xml文件中,尝试删除ConstraintLayout中的android:paddingTop=?attr/actionBarSize行,因为activity\u main.xml文件中没有actionBar。

,尝试删除ConstraintLayout中的android:paddingTop=?attr/actionBarSize行,因为没有操作栏。

我看到您的活动布局中有android:paddingTop=?attr/actionBarSize,但您没有操作栏。这不就跟去掉那个填充物一样简单吗?米切尔,就是这么简单我看到您的活动布局中有android:paddingTop=?attr/actionBarSize,但您没有
有一个动作条。这不就跟去掉那个填充物一样简单吗?米切尔,就是这么简单Mayokun的解决方案奏效了,但你的解决方案确实起了作用。谢谢Mayokun的解决方案奏效了,但你的解决方案确实起了作用。谢谢