AndroidX Horizontal RecyclerView wrap_content not working?

1.5k Views Asked by At

RecyclerView horizontal was worked in support library. after converting to androidx is not working when using the wrap_content.

My layout looks like this

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvPlannedDays"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary" />

Java File look like this

RecyclerAdapter recyclerAdapter = new RecyclerAdapter(list);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(viewDietChartDayRecyclerAdapter);

EDIT: Item row

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tvDayCount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorDanger"
    android:text="1"
    android:layout_gravity="center"
    android:textColor="@color/colorPrimaryText"
    android:textSize="@dimen/sub_heading" />

Adapter's onCreateViewHolder

@NonNull
@Override
public DayViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View listItemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_item_view_day, parent, false);
    return new DayViewHolder(listItemView);
}

This is not working How to fix this issue?

If anyone tried horizontal recyclerview with AndroidX Please let me fix this guys.

I found the issue, I'm adding that fragment to view pager but I want horizontal recycler view inside view pager. this also not working. I tried setting nestedScrolledEnabled=true to recyclerView. Still its not working

0

There are 0 best solutions below