Adding RecyclerView inside of DrawerLayout

前端 未结 1 1872
渐次进展
渐次进展 2020-12-18 13:13

I wish to be able to have a RecyclerView inside the main page of a DrawyerLayout MainActivity. However, adding my code as below does n

相关标签:
1条回答
  • 2020-12-18 13:44

    First, you can remove android:padding="16dp" from the LinearLayout, that is why you see "blank space" around the list.

    Then you want wrap_content height on the <include-d app bar layout so that it does not take the whole space.

    And simply move the LinearLayout outside of the NavigationView

    <?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"
        ...
    
    
        <!-- here is the content -->
        <LinearLayout
            android:orientation="vertical"
            ...
            >
    
            <!-- here is the toolbar -->
            <include
                layout="@layout/app_bar_main"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    
            ...
            <RecyclerView
                ...
                />
        </LinearLayout>
    
        <!-- here is the drawer -->
        <NavigationView
            android:layout_gravity="start"
            ... >
    
        </NavigationView>
    
    </DrawerLayout>
    
    0 讨论(0)
提交回复
热议问题