Reputation: 303
I am designing a shopping app via Kotlin & Firebase. I am using recycler view in an inbuilt fragment . There is one activity which is responsible for multiple fragments , for example one fragment is responsible for displaying orders , one fragment is responsible displaying all products etc. I get all my data from firebase & display it in fragments via a recycler view. The issue is that the recycler view scrolls but it does not scroll to the end of the page. Can someone guide me. I have attached two screenshots
(Recycler view does not scroll to the end of the last child i.e "TAP TO KNOW MORE" textview is not visible for the last element of recycler view, it just stops scrolling)
This is how my activity is designed ->
<?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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="@color/purple_500"
app:itemIconTint="@color/white"
app:itemTextColor="@color/bgColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:labelVisibilityMode="unlabeled"
app:menu="@menu/bottom_nav_menu" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation"/>
</androidx.constraintlayout.widget.ConstraintLayout>
This is how my fragment is designed ->
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.ui.fragments.DashboardFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_dashboard_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:id="@+id/tv_no_dashboard_item_found"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
android:text="@string/no_dashboard_item_found"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is how my recycler view item is designed ->
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="265dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:id="@+id/view"
android:layout_width="180dp"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
app:cardElevation="10dp"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/iv_item_image_dashboard"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
/>
<com.example.shopperista.utils.CustomTextViewStyleBold
android:id="@+id/tv_item_name_dashboard"
android:layout_marginTop="10dp"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="@string/guitar"
android:textSize="14sp"
android:layout_marginStart="10dp"
/>
<com.example.shopperista.utils.CustomTextViewStyle
android:id="@+id/tv_item_price_dashboard"
android:layout_marginTop="10dp"
android:layout_width="150dp"
android:paddingTop="2dp"
android:layout_height="wrap_content"
android:textSize="12sp"
android:paddingBottom="10dp"
android:text="@string/rs_2500"
android:layout_marginStart="10dp"
/>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="10dp"
app:cardCornerRadius="20dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="15dp"
android:layout_gravity="center">
<TextView
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tap_to_know_more"
android:textSize="10sp"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 2
Views: 514
Reputation: 393
Make android:layout_height="0dp"
in your fragment, your bottom navigation is overlapping on top of your fragment
Upvotes: 1
Reputation: 1725
Change the XML for <fragment>
as follows:
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation"/>
The main part is changing the android:layout_height
from match_parent
to 0dp
as you want the fragment to take the remaining space after excluding the bottom navigation. If you use match_parent
, the bottom part of the fragment hides behind the bottom navigation bar
Upvotes: 2