Java 片段、框架布局如何使其可滚动?
我很困惑,我有3个片段和抽屉视图的应用程序。我需要将项目放入列表中,并能够向下滚动,如果我更改布局,我会出错,请查看我的xml,+我有点困惑,我应该将我的内容(main_activity.xml或fragment_home.xml)放在哪里,因为如果我将任何内容放入其中,就会出现内容。多谢各位Java 片段、框架布局如何使其可滚动?,java,android,xml,android-fragments,android-framelayout,Java,Android,Xml,Android Fragments,Android Framelayout,我很困惑,我有3个片段和抽屉视图的应用程序。我需要将项目放入列表中,并能够向下滚动,如果我更改布局,我会出错,请查看我的xml,+我有点困惑,我应该将我的内容(main_activity.xml或fragment_home.xml)放在哪里,因为如果我将任何内容放入其中,就会出现内容。多谢各位 <!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
/>
</FrameLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
主要活动
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
/>
</FrameLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
PS-此时根本没有任何内容,只有一个带3点按钮的工具栏出现,可以打开抽屉(或者您可以滑动到抽屉),还有一个菜单可以访问其他片段。将您的片段\u home.xml的父对象设置为NestedScrollView,因此,对于片段,请使用fragment\u home.xml;对于活动,请使用activity\u main.xml
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
/>
</FrameLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
如果您是新的,那么创建新项目并选择NavigationDrawer,它将提供现成的模板 好的,我可以将fragment_home.xml中的“FrameLayout”更改为NestedScrollView,并且?“对于fragment使用fragment_home.xml,对于您的活动使用activity_main.xml”-在Android开发两年后,您不明白这意味着什么吗?我做了一段时间这个项目,抽屉工作正常,我不需要做新的项目。当我把它改成NestedScrollView后,我的3点按钮停止工作,我只能通过滑动((工具栏变为非活动状态)来进入抽屉(
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
/>
</FrameLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>