[英]Fragments, FrameLayout how to make is scrollable?
我很困惑,我有3個片段和DrawerView的應用程序。 我需要將項目放在列表中並能夠向下滾動,如果更改布局,會出現錯誤,請查看我的XML,+有點困惑,我應該在哪里放置內容(main_activity.xml或fragment_home.xml),因為如果我將任何內容放入其中,內容就會出現。 謝謝。
activity_main
<!-- 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>
fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment">
</FrameLayout>
這個在我的“ Home Fragment” java文件中聲明
public class HomeFragment extends Fragment {
public HomeFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
}
}
PS-暫時沒有任何內容,只有工具欄帶有3點按鈕出現,該按鈕打開抽屜(或者您可以滑動到那里),並且有一個菜單可以到達其他片段。
將fragment_home.xml的父級設置為NestedScrollView,因此對於fragment,請使用fragment_home.xml,對於您的活動,請使用activity_main.xml。
如果您是新手,則創建新項目並選擇NavigationDrawer,它將提供現成的模板。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.