0
votes

enter image description hereenter image description here <androidx.coordinatorlayout.widget.CoordinatorLayout 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"[![enter image description here][2]][2] android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/rootLayout_survey_ques" tools:context=".survey.SurveyQuesActivity">

<include layout="@layout/toolbar"
    android:id="@+id/survey_ques_toolbar"/>

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/survey_ques_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/survey_ques_toolbar"
    android:layout_marginTop="2dp" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp"
    android:elevation="10dp"
    android:id="@+id/fab_submit"
    android:src="@drawable/ic_submit" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

when fab is clicked, snack bar appears, for that I have to use coordinator layout to move the fab horizontally above snack bar. But now the first few items of recycler view is not visible. It only starts with item3. Can someone pls help in solving this and what changes to be made. Thanks in advance!!

5
there is nothing wrong with your layout, bug is probably in adapter for RecyclerView. show its code and some screen how it looks and, if possible, how should besnachmsm
@snachmsm, i have added the picture of layoutvishnu jm
Did You try Scrolling Down?Sahil Goyal
@SahilGoyal yes, in output half of the first item is missingvishnu jm

5 Answers

2
votes

You don't need to use marginTop or RelativeLayout there is already solution for this case in CoordinatiorLayout: layout_behaviour Try using this structure in your main XML and add scrolling layout behaviour for RecyclerView

<androidx.coordinatorlayout.widget.CoordinatorLayout...
<com.google.android.material.appbar.AppBarLayout...
   <androidx.appcompat.widget.Toolbar...

</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/survey_ques_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
  app:layout_behavior = "com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>
0
votes

you are using layout_below for RecyclerView, but this attribute is intended to be used by RelativeLayout childrens, not CoordinatorLayout. so your items are there, but they are covered by Toolbar, as RecyclerView doesn't respect attr telling to align below Toolbar. Change your main container for RelativeLayout to get layout_below attribute working

<RelativeLayout
    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:id="@+id/rootLayout_survey_ques"
    tools:context=".survey.SurveyQuesActivity">
...
</RelativeLayout>

note that android:layout_gravity="bottom|end" attribute set for FloatingActionButton will stop working, as this attr is inteneded to use with LinearLayout or FrameLayout, not RelativeLayout. you may want to use instead

android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"

edit: good point in comment. instead of above suggestions maybe try to add proper top margin for RecyclerView for placing it below Toolbar

android:layout_marginTop="?attr/actionBarSize"
0
votes

It seems your recyclerView is covered by included toolbar layout. Can you try adding top margin as same of height of your toolbar layout if hardcoded or if you used default Height ?attr/actionBarSize

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/survey_ques_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/survey_ques_toolbar"
android:layout_marginTop="?attr/actionBarSize" /><!-- or height you gave in toolbar layout -->
0
votes

Put recyclerview inside Relative layout or any other layout like below:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
    tools:context=".MainActivity">
//Toolbar


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/survey_ques_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="2dp" />
    </RelativeLayout>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
0
votes

add recyclerview this code app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"