gpt4 book ai didi

android - 使 Android 抽屉导航可滚动

转载 作者:行者123 更新时间:2023-11-29 01:10:26 24 4
gpt4 key购买 nike

我有一个包含三个部分的抽屉导航,顶部、中间和底部我需要使中间部分可以滚动。

enter image description here

这是我当前的布局。

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<!-- begin Top Section-->
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_black"
android:paddingLeft="50dp"
app:headerLayout="@layout/nav_header_main"
/>
<!--End Top Section-->
<!-- begin Middle Section-->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_top"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top"
android:background="@color/menuColor"
android:paddingLeft="50dp"
app:itemTextAppearance="@style/NavigationDrawerStyle"
app:menu="@menu/menu_navigation_drawer_top"
app:itemTextColor="@color/menuTextColour" />
<!-- End Middle Section-->
<!-- begin Bottom Section-->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/background_black"
app:headerLayout="@layout/nav_group_line"
app:itemTextColor="@color/menuTextColour">

<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/menuColor_bottom"
android:paddingLeft="50dp"
app:itemTextAppearance="@style/NavigationDrawerStyle"
app:itemTextColor="@color/menuTextColour"
app:menu="@menu/menu_navigation_drawer_bottom" />
</android.support.design.widget.NavigationView>
<!-- End Bottom Section-->

</android.support.design.widget.NavigationView>

如何在我的导航 View 中使中间部分可缩放。

最佳答案

NavigationView 为您提供 attr app:headerLayout 用于添加导航标题。要添加页脚,只需将所需的页脚 View 包装在 NavigationView 中即可,

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
>

<LinearLayout
android:background="@android:color/darker_gray"
android:clickable="true"
android:id="@+id/ll_header"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">

<TextView
android:gravity="center"
android:id="@+id/nav_header_textview"
android:layout_height="48dp"
android:layout_width="match_parent"
android:text="Your Header Text Here" />

</LinearLayout>

<android.support.design.widget.NavigationView
android:layout_below="@+id/ll_header"
android:layout_above="@+id/ll_footer"
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/my_navigation_items" >


</android.support.design.widget.NavigationView>

<LinearLayout
android:id="@+id/ll_footer"
android:background="@android:color/darker_gray"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">

<TextView
android:gravity="center"
android:id="@+id/nav_footer_textview"
android:layout_height="48dp"
android:layout_width="match_parent"
android:text="Your Footer Text Here" />

</LinearLayout>

</RelativeLayout>

为了举例,我使用了 TextView。

关于android - 使 Android 抽屉导航可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43604762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com