as you can see in the screenshot, in my recyclerview (in activity_main) I have items with huge empty vertical space, between recyclerview and appbarlayout.
The Code Itself.
activity_main
<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:layoutDirection="rtl">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?colorPrimary"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/layout_app_feature" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/layout_navigation_header"
app:menu="@menu/navigation_menu" />
</android.support.v4.widget.DrawerLayout>
layout_app_feature in this layout, I'm trying to show some items that have an image with a caption(TextView)
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/standard_margin"
android:layout_marginLeft="@dimen/standard_margin"
android:layout_marginTop="@dimen/small_margin"
android:layout_marginBottom="@dimen/small_margin"
app:cardElevation="@dimen/standard_card_Elevation"
app:cardCornerRadius="@dimen/standard_card_Radius">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?attr/selectableItemBackground"
android:padding="@dimen/standard_margin">
<ImageView
android:id="@+id/feature_image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/standard_margin"
android:layout_marginTop="@dimen/standard_margin"
android:adjustViewBounds="true" />
<TextView
android:id="@+id/feature_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/standard_margin"
android:paddingLeft="@dimen/standard_margin"
android:paddingRight="@dimen/standard_margin"
android:layout_below="@id/feature_image_view"
android:gravity="right"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
activity_banner_slider and also I have an activity to show top banner slider and a toolbar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".view.TopBannerSlider">
<com.daimajia.slider.library.SliderLayout
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="200dp"
app:indicator_visibility="invisible" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/standard_card_Elevation">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/standard_margin">
<ImageView
android:id="@+id/icon_list"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentStart="true"
app:srcCompat="@drawable/ic_menu_list" />
<TextView
android:id="@+id/label_app_features_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/icon_list"
android:text="دسترسی سریع" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
layout_navigayion_heaader
and a layout to show navigation view
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/navigation_header_image"
android:layout_width="match_parent"
android:layout_height="220dp"
android:adjustViewBounds="true"
android:src="@drawable/navigation_header"
android:scaleType="centerCrop"/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/standard_margin_x2"
android:src="@drawable/default_avatar"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_margin_x2"
android:textColor="@color/white"
android:textSize="15dp"
android:text="نام کاربری: Mohammad"
android:layout_alignBottom="@id/navigation_header_image"
/>
</RelativeLayout>
I checked everything in my code but I have no idea why
Anybody knows why?
finally, I found the problem
in activity_banner_slider at LinearLayout
I should set android:layout_height="match_parent
"
to wrap_content