Unable to scroll through the activity - android

I have the following activity where I have an imageview , 2 flipper views and a gridview along with a navigation drawer.As gridView is a scroll enabled activity by default ,earlier only my gridview was scrollable. I wanted my whole activity to be scrollable instead of just the gridView , so for that I put my frameLayout inside a nestedScrollView.
I also set grid.setNestedScrollingEnabled(false) in my MainActivity.java .
Here's my xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:nestedScrollingEnabled="true"
tools:context="com.example.xxx.xxx.MainActivity"
app:layout_behavior="android.support.design.widget.AppBarLayout.ScrollingViewBehaviour">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frameLayout">
<android.support.constraint.ConstraintLayout 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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff"
android:fitsSystemWindows="true"
android:isScrollContainer="true"
android:orientation="vertical"
tools:context="com.example.xxx.xxx.MainActivity">
<ImageView
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="61dp"
android:scaleType="fitXY"
android:src="#drawable/banner1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="#string/todo" />
<technolifestyle.com.imageslider.FlipperLayout
android:id="#+id/flipper"
android:layout_width="wrap_content"
android:layout_height="66dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/b1" />
<technolifestyle.com.imageslider.FlipperLayout
android:id="#+id/Flipper2"
android:layout_width="wrap_content"
android:layout_height="67dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/flipper">
</technolifestyle.com.imageslider.FlipperLayout>
<GridView
android:id="#+id/grid"
android:layout_width="wrap_content"
android:layout_height="542dp"
android:background="#ffff"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="3"
android:padding="2dp"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Flipper2"
app:layout_constraintVertical_bias="0.615" />
</android.support.constraint.ConstraintLayout>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.NavigationView
android:id="#+id/navView"
android:layout_width="200dp"
android:layout_height="match_parent"
app:menu="#menu/navigation_menu"
android:background="#ffff"
app:itemTextColor="#0f0f0f"
android:layout_gravity="start"
app:itemIconTint="#color/black_overlay"
android:fitsSystemWindows="true"/>
</android.support.v4.widget.DrawerLayout>

Related

add version of app at bottom navigation view is not displayed properly

As a lot of people are probably trying to do it, I am trying to add a footer to a navigation view. I did this:
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/background"
android:clipToPadding="true"
app:headerLayout="#layout/layout_nav_header"
app:menu="#menu/navigation_menu">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="24dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:gravity="left"
android:text="#string/appVersion"/>
<TextView
android:id="#+id/buildInfoTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</com.google.android.material.navigation.NavigationView>
This working fine but not in 2 cases: small screen because the linearlayout overlap the menu and also if the keyboard is popped up, it move the layout.
Any idea how to make sure that the linear layout with the app version stick to the bottom of the navigation or also below the menu item so it's not overlapping on small screen.
Thanks
Try this once
Note change widget values and parameters as per your requirements.
OPTION 1-
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:headerLayout="#layout/content_main"
app:layout_constraintBottom_toTopOf="#+id/linearLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="#menu/menu_main" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start|center"
android:text="#string/app_name" />
<TextView
android:id="#+id/buildInfoTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start|center"
android:text="#string/app_name" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
OPTION 2-
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/linear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:headerLayout="#layout/content_main"
app:menu="#menu/menu_main" />
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start|center"
android:text="#string/app_name" />
<TextView
android:id="#+id/buildInfoTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start|center"
android:text="#string/app_name" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Using DrawerLayout with BottomSheetBehavior

I have a problem when opening DrawerLayout while having BottomSheetBehavior at the bottom of the layout. BottomSheetBehavior layout is hidden at the moment, but the DrawerLayout is cropped at a place where is BottomSheetBehavior layout top height.
Any ideas?
DrawerLayout with BottomSheetBehavior
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.some.example.widgets.SearchBarWidget
android:id="#+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.some.example.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="#+id/map"
app:layout_constraintEnd_toEndOf="#+id/map"
app:layout_constraintStart_toStartOf="#+id/map"
app:layout_constraintTop_toTopOf="#+id/map" />
</androidx.constraintlayout.widget.ConstraintLayout>
<include layout="#layout/layout_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header"
app:menu="#menu/navigation_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
layout_bottom_sheet.xml
<?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:id="#+id/bottomSheetLayout"
android:layout_width="match_parent"
android:layout_height="240dp"
android:background="#drawable/bottom_sheet_background"
android:orientation="vertical"
android:paddingTop="0dp"
app:behavior_hideable="true"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<LinearLayout
android:id="#+id/gestureLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingTop="10dp">
<ImageView
android:id="#+id/expandCollapseImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/expand"
tools:ignore="ContentDescription" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I rearranged layout like that, I put ConstraintLayout outside CoordinatorLayout and it worked.
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.some.example.widgets.SearchBarWidget
android:id="#+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.some.example.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="#+id/map"
app:layout_constraintEnd_toEndOf="#+id/map"
app:layout_constraintStart_toStartOf="#+id/map"
app:layout_constraintTop_toTopOf="#+id/map" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000">
<include layout="#layout/layout_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header"
app:menu="#menu/navigation_menu" />
</androidx.drawerlayout.widget.DrawerLayout>

How to bring the FAB to the top of the layout

I am trying to have 3 FAB's between two views. But the FAB's are below the top view as shown below.
How do I bring them to the front?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:clickable="true"
android:focusableInTouchMode="true"
android:id="#+id/parentPanel"
android:background="#ffffff">
<LinearLayout
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="6dp"
android:layout_margin="10dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:id="#+id/deviceCard">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.tegaru.beepr.AddNewMapsLocationActivity" />
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/bottomPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="4"
android:background="#android:color/white">
<LinearLayout
android:id="#+id/btnPanel1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:background="#android:color/white">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="AddNewReminderBtnClicked"
app:backgroundTint="#292929"
app:fabSize="normal"
app:srcCompat="#drawable/ic_menu_send"
android:layout_gravity="top|center"
android:layout_marginTop="-20dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnPanel2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:background="#android:color/white">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="AddNewReminderBtnClicked"
app:backgroundTint="#292929"
app:fabSize="normal"
app:srcCompat="#drawable/ic_menu_send"
android:layout_gravity="top|center"
android:layout_marginTop="-20dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnPanel3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:background="#android:color/white">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="AddNewReminderBtnClicked"
app:backgroundTint="#292929"
app:fabSize="normal"
app:srcCompat="#drawable/ic_menu_send"
android:layout_gravity="top|center"
android:layout_marginTop="-20dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
LinearLayout does not allow children views to be overlapped.
You should use RelativeLayout (or FrameLayout, etc) instead of LinearLayout as the parent if you want to display FABs above (overlapping) other views.
In your case, set the root layout to RelativeLayout. You may need to make other adjustments though.
To space the fabs equally and use them as an overlay for a web view for example, look at my code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:theme="#style/ThemeOverlay.AppCompat.Dark">
<WebView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></WebView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/fab2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/fab3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/fab1" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/fab2" />
</android.support.constraint.ConstraintLayout>

Add SearchView to RecyclerView List

I have a recyclerview populated with a list from an API. I am using RxBinding to search and filter the list. The current problem is with my layout. I would like my search bar field at the top with the list beneath it. Below is an example of my list being filtered but as you can see the searchbar text and the List Items overlap
Now below is the layout file.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<android.support.v7.widget.RecyclerView
android:id="#+id/listRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/searchView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_weight="1"
android:background="#android:color/transparent"
android:inputType="text" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end|center_vertical"
android:src="#android:drawable/ic_menu_search" />
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
Eventually I want the searchbar to be scrollable as well, so that when the user scrolls down the list, the searchbar will be rotated out. However I think this will involve me created a list of some CommonInterface which my both my SearchBar and ListItems would have to implement.
Use RelativeLayout like this so that recyclerView is below the editText and add a scrollView so that the scrolling happens on the whole layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/listRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edit"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/searchView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_weight="1"
android:background="#android:color/transparent"
android:inputType="text" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end|center_vertical"
android:src="#android:drawable/ic_menu_search" />
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And add this in your RecyclerView in Java:
recyclerView.setNestedScrollingEnabled(false);
You can try this layout
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#color/atehensGray"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/chrome_grey"
android:fitsSystemWindows="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="#drawable/rounded_corners"
android:gravity="top"
android:hapticFeedbackEnabled="true"
android:orientation="horizontal"
android:visibility="visible"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1.0" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/white"
android:id="#+id/recyclerView_main"
android:layout_width="0dp"
android:layout_height="0dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/appBarLayout" />
</android.support.constraint.ConstraintLayout>

Android recyclerview items overlap screen

In my android app I have a recyclerview inside my main activity.
These recyclerview is supposed to display documents to the user.
My problem is that the items overlap the right part of the screen. I don't know why it happens. I have worked with CardViews before but I can't seem to solve this.
Here is a screenshot of my problem:
As you can see, the right side of the CardViews overlaps the screen.
Here is the main activity layout code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/top_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackground"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<include layout="#layout/toolbar"
android:id="#+id/toolbar_layout"
tools:layout_constraintTop_creator="1"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="384dp"
android:layout_height="567dp"
android:fitsSystemWindows="true"
tools:layout_constraintTop_creator="1"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.silverfix.dgdeditor.utils.views.EmptyViewRecyclerView
android:id="#+id/documents_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:focusable="true"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:listitem="#layout/document_list_item" />
<ImageView
android:id="#+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/empty_view"
android:scaleX="0.5"
android:scaleY="0.5" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="?attr/actionBarSize"
android:background="#drawable/menu_background"
android:fitsSystemWindows="true"
android:padding="10dp"
app:menu="#menu/nav_drawer_menu"
app:headerLayout="#layout/nav_header"
app:itemTextAppearance="#style/NavDrawerTextStyle" />
</android.support.v4.widget.DrawerLayout>
</android.support.constraint.ConstraintLayout>
And here is the document_list_item code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/dg_card_view"
android:layout_width="match_parent"
android:layout_height="#dimen/dg_card_view_height"
android:clickable="true"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="3dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="#drawable/nav_item_divider" />
<TextView
android:id="#+id/document_card_name_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/card_side_padding"
android:text="Document: "
android:textAppearance="#style/TextAppearance.AppCompat" />
<TextView
android:id="#+id/document_card_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/document_card_name_tv"
android:layout_marginRight="#dimen/card_side_padding"
android:text="Date"
android:textAppearance="#style/TextAppearance.AppCompat" />
</RelativeLayout>
</android.support.v7.widget.CardView>

Categories

Resources