I have a recycler view inside fragment "Home" and it is not scrolling vertically. Can someone please help me out !! My fragment is inside home screen containing a toolbar, drawer navigation and bottom tab navigation . i got another recycler view inside home fragment and that recycler view is not scrolling
This recyclerView is not scrolling >>>
Here is my HomeScreen code
<?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=".homeSc"
android:id="@ id/constraintLayout">
<FrameLayout
android:id="@ id/frameLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@ id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" />
<androidx.drawerlayout.widget.DrawerLayout
android:id="@ id/drawerNavigationDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@ id/drawerNavigationToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#B3E3E1"
android:elevation="4dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@color/black"/>
<FrameLayout
android:id="@ id/drawerNavigationFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"/>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@ id/drawerNavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_nav_header"
app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Here is my Home Fragment Code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@ id/frameLayoutHomeSc"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/recyclerVFragHomeSc"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
Recycler View Adapter Code
package com.example.knowledgespaceapk;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class adapterRecVHomeFrag extends RecyclerView.Adapter<adapterRecVHomeFrag.myviewholder>{
ArrayList<dataModelRecVFragHome> dataHolder;
public adapterRecVHomeFrag(ArrayList<dataModelRecVFragHome> dataHolder) {
this.dataHolder = dataHolder;
}
@NonNull
@Override
public myviewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new myviewholder(LayoutInflater.from(parent.getContext()).inflate(R.layout.single_row_design_rec_homef
,parent,false));
}
@Override
public void onBindViewHolder(@NonNull myviewholder holder, int position) {
holder.img.setImageResource(dataHolder.get(position).getImage());
holder.title.setText(dataHolder.get(position).getTitle());
holder.desc.setText(dataHolder.get(position).getDescription());
}
@Override
public int getItemCount() {
return dataHolder.size();
}
class myviewholder extends RecyclerView.ViewHolder{
ImageView img;
TextView title,desc;
public myviewholder(@NonNull View itemView) {
super(itemView);
img = itemView.findViewById(R.id.imageVSingleRowDesRecHomeF);
title = itemView.findViewById(R.id.titleTxtVSingleRDesRecHomeF);
desc = itemView.findViewById(R.id.descriptionTxtVSingleRDesRecHomeF);
}
}
}
Recyler View Element layout Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="5dp"
android:elevation="4dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@ id/imageVSingleRowDesRecHomeF"
android:layout_width="match_parent"
android:layout_height="219dp"
android:visibility="visible"
app:srcCompat="@drawable/fest" />
<TextView
android:id="@ id/titleTxtVSingleRDesRecHomeF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@ id/descriptionTxtVSingleRDesRecHomeF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="8dp"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
Home Screen Java Code
package com.example.knowledgespaceapk;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.os.Bundle;
import com.example.knowledgespaceapk.databinding.ActivityHomeScBinding;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class homeSc extends AppCompatActivity {
private DrawerLayout drawerLayout;
private BottomNavigationView bottomNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_sc);
Toolbar toolbar = findViewById(R.id.drawerNavigationToolbar);
setSupportActionBar(toolbar);
drawerLayout = findViewById(R.id.drawerNavigationDrawerLayout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawerLayout,
toolbar,R.string.open,R.string.close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
replaceFrag(new HomeFragment());
bottomNavigationView = findViewById(R.id.bottomNavigationView);
bottomNavigationView.setOnItemSelectedListener(item -> {
switch (item.getItemId()){
case R.id.home : replaceFrag(new HomeFragment()); break;
case R.id.group: replaceFrag(new GroupFragment()); break;
case R.id.notification:replaceFrag(new NotificationFragment()); break;
}
return true;
});
}//End OnCreate
@Override
public void onBackPressed() {
if(drawerLayout.isDrawerOpen(GravityCompat.START)){
drawerLayout.closeDrawer(GravityCompat.START);
}else {
super.onBackPressed();
}
}
private void replaceFrag(Fragment fragment){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frameLayout,fragment);
fragmentTransaction.commit();
}
}//End Main
CodePudding user response:
Try to set the DrawerLayout
as parent view in your HomeScreen XML:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@ id/drawerNavigationDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".homeSc"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@ id/constraintLayout">
<FrameLayout
android:id="@ id/frameLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@ id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@ id/drawerNavigationToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#B3E3E1"
android:elevation="4dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@color/black"/>
<FrameLayout
android:id="@ id/drawerNavigationFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"/>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@ id/drawerNavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_nav_header"
app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>