Java 片段布局与活动标题栏重叠
我有一个活动,这是一个材料设计抽屉,当用户单击抽屉的一个选项时,从活动java文件调用一些片段。 问题是片段布局与活动标题栏重叠,与所有屏幕匹配,而不是位于活动内部。 在AndroidStudio预览中,片段内容设置正确: 但当我将apk加载到手机中时,我看到如下内容: 以下是我的源代码: -fragment_layout.xmlJava 片段布局与活动标题栏重叠,java,android,android-layout,android-fragments,Java,Android,Android Layout,Android Fragments,我有一个活动,这是一个材料设计抽屉,当用户单击抽屉的一个选项时,从活动java文件调用一些片段。 问题是片段布局与活动标题栏重叠,与所有屏幕匹配,而不是位于活动内部。 在AndroidStudio预览中,片段内容设置正确: 但当我将apk加载到手机中时,我看到如下内容: 以下是我的源代码: -fragment_layout.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="ht
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<EditText
android:id="@+id/subjectSelector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Write subject initials"/>
<Button
android:id="@+id/queryButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:text="Search"
android:layout_alignBottom="@+id/subjectSelector"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/subjectSelector"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/subjectName"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/subjectTeachers"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/subjectDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/subjectCredits"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
- MainMenu.xml(抱歉,我无法将其更新为代码格式)
- app_bar_main_menu.xml
- content\u main\u menu.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_menu_fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" />
我怎样才能解决这个问题呢?我得到了答案,那只是一件愚蠢的事情。在content_main_menu.xml上,框架布局与所有屏幕匹配,因此我只需留下一个actionBarSize的marginTop。这是新的content_main_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_menu_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"/>
你能分享你的
应用程序工具栏主菜单.xml
?以及任何其他后续布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_menu_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_menu_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"/>