Я пытаюсь реализовать горизонтальный вид рециркулятора внутри вертикального ракурса и так, чтобы я прокручивал горизонтальные элементы по два за раз. Данные поступают из API. Но горизонтальный вид переработчика не может правильно загрузить данные, и приложение прокручивается при прокрутке. Я исследовал всюду по стеку для решения, но все еще я не мог получить один. Ниже приведен мой код:
Адаптер OuterRecyclerView (Вертикаль):
public class CategoryBannerAdapter extends RecyclerView.Adapter<CategoryBannerAdapter.CategoryBannerViewHolder> {
private final RecyclerView.RecycledViewPool viewPool;
Context context;
List<Datum> bannerList;
ICartDelegate listener;
private static final String TAG = "CategoryBannerAdapter";
public CategoryBannerAdapter(Context context, List<Datum> bannerList, ICartDelegate listener) {
this.context = context;
this.bannerList = bannerList;
this.listener = listener;
viewPool = new RecyclerView.RecycledViewPool();
}
@NonNull
@Override
public CategoryBannerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.category_banner_cell, null, false);
return new CategoryBannerViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull CategoryBannerViewHolder holder, int position) {
final Datum datum = bannerList.get(position);
LinearLayout a = null;
Picasso.get().load(datum.getBanner().getBannerImg()).placeholder(R.drawable.hapdel_logo_small).fit().into(holder.banner_img);
holder.banner_title_text.setText(datum.getBanner().getTitle());
holder.view_more_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, OpenProductActivity.class);
com.utility.hapdel.Model.CategoryModel.ParentCategoryModel.Datum datum1 = new com.utility.hapdel.Model.CategoryModel.ParentCategoryModel.Datum();
datum1.setId(datum.getBanner().getCategoryId());
intent.putExtra("category", new Gson().toJson(datum1));
context.startActivity(intent);
}
});
holder.product_title.setText(datum.getBanner().getTitle());
holder.product_recycler_view.setNestedScrollingEnabled(false);
if(datum.getItems()!=null && datum.getItems().size()>=0){
Log.d(TAG, "onBindViewHolder: mitems size "+datum.getBanner().getTitle()+" "+ datum.getItems().size());
int indiator_size = (int) Math.ceil((Double.valueOf(datum.getItems().size()))/ 2);
holder.productsAdapter.updateItems(datum.getItems());
holder.productsAdapter.setRowIndex(position);
//adding circle indicator to recyclerview
holder.circleIndicator.setItemCount(indiator_size);
holder.circleIndicator.setCurrentPosition(0);
}
}
@Override
public int getItemCount() {
return bannerList.size();
}
public void updateItems(List<Datum> data) {
if(data !=null){
bannerList = data;
notifyDataSetChanged();
}
}
public class CategoryBannerViewHolder extends RecyclerView.ViewHolder{
private final GridLayoutManager gridLayoutManager;
private ProductsAdapter productsAdapter;
private RecyclerView product_recycler_view;
private TextView banner_title_text;
private ImageView banner_img;
private RelativeLayout root_layout;
private TextView view_more_btn;
private TextView product_title;
private AnyViewIndicator circleIndicator;
private Context mContext;
public CategoryBannerViewHolder(@NonNull View itemView) {
super(itemView);
banner_img = itemView.findViewById(R.id.banner_img);
root_layout = itemView.findViewById(R.id.root_layout);
product_recycler_view = itemView.findViewById(R.id.product_recycler_view);
mContext = itemView.getContext();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0,context.getResources().getDimensionPixelOffset(R.dimen._15sdp),0,context.getResources().getDimensionPixelOffset(R.dimen._10sdp));
root_layout.setLayoutParams(layoutParams);
banner_title_text = itemView.findViewById(R.id.banner_title_text);
view_more_btn = itemView.findViewById(R.id.view_more_btn);
product_title = itemView.findViewById(R.id.product_title);
circleIndicator = itemView.findViewById(R.id.banner_indicator1);
gridLayoutManager = new GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, false);
product_recycler_view.setLayoutManager(gridLayoutManager);
productsAdapter = new ProductsAdapter(context, new ArrayList<Product>(), listener);
product_recycler_view.setAdapter(productsAdapter);
}
}
}
ParentRecyclerView XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/_20sdp"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/banner_title_text"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_5sdp"
android:textSize="@dimen/_13ssp"
android:theme="@style/banner_title" />
<View
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginBottom="@dimen/_7sdp"
android:background="@drawable/faded_line"
android:paddingHorizontal="@dimen/_12sdp"></View>
<androidx.cardview.widget.CardView
android:id="@+id/banner_card"
android:layout_marginTop="@dimen/_5sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/_5sdp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true"
>
<ImageView
android:id="@+id/banner_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="#10000000" />
<ImageView
android:id="@+id/banner_logo"
android:layout_width="@dimen/_24sdp"
android:layout_height="@dimen/_24sdp"
android:elevation="@dimen/_20sdp"
android:layout_alignParentStart="true"
android:layout_margin="@dimen/_5sdp"
android:background="@drawable/logo"
android:visibility="gone" />
<TextView
android:id="@+id/banner_logo_txt"
style="@style/banner_logo"
android:layout_width="wrap_content"
android:elevation="@dimen/_10sdp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_5sdp"
android:layout_toRightOf="@id/banner_logo"
android:text="hapdel"
android:visibility="gone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:elevation="@dimen/_10sdp"
android:layout_gravity="bottom"
android:textColor="@color/colorPrimaryGreen"
android:layout_margin="@dimen/_10sdp"
android:text="Best Price Guaranteed"
android:theme="@style/banner_offer"
android:visibility="gone" />
<TextView
android:id="@+id/product_title"
android:layout_width="wrap_content"
android:layout_height="@dimen/_25sdp"
android:background="@drawable/banner_btn"
android:text="GRAB"
android:textColor="@color/colorWhite"
android:gravity="center"
android:paddingHorizontal="@dimen/_5sdp"
android:textAlignment="center"
android:layout_margin="@dimen/_5sdp"
android:elevation="@dimen/_100sdp"
android:visibility="visible" />
<View
android:id ="@+id/empty_view"
android:background="@color/colorPrimaryGreen"
android:layout_height="@dimen/_10sdp"
android:layout_width="match_parent"
android:visibility="invisible"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:id="@+id/title_horizontalScrollView"
android:layout_margin="1dp"
android:fillViewport="false">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listview"
android:drawSelectorOnTop="true"
android:gravity="center"
android:scrollbars="horizontal"></GridView>
</LinearLayout>
</HorizontalScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_5sdp"
android:descendantFocusability="blocksDescendants">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/product_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:elevation="@dimen/_20sdp"
android:orientation="horizontal"></androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
<com.kingfisher.easyviewindicator.AnyViewIndicator
android:id="@+id/banner_indicator1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
app:avi_animation_enable="false"
app:avi_drawable="@drawable/blue_radius"
app:avi_drawable_unselected="@drawable/gray_radius"
app:avi_height="10dp"
app:avi_margin="10dp"
app:avi_orientation="horizontal"
app:avi_width="10dp"
/>
<TextView
android:id="@+id/view_more_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/_5sdp"
android:textStyle="bold"
android:drawableEnd="@drawable/ic_chevron_right_black_24dp"
android:text="View More"
android:textColor="@color/colorPrimary"
android:textSize="@dimen/_12ssp" />
</LinearLayout>
</RelativeLayout>
Данные из API:
{
"result": "success",
"response_code": 200,
"msg": 5,
"data": [
{
"banner": {
"title": "Instant Yummy Maggie",
"banner_img": "https://hapdel.com/assets/uploads/c65e1450352d2f07c7ef1f6451f31f3c.jpg",
"category_id": "70",
"product_category_id": "80"
},
"items": [
{
"pid": "96",
"seller_id": "2",
"store_name": "Fresh Menu",
"image": "353ac8c1b39f076c335a3abf902a96a8.jpg",
"type": "product",
"category_id": "80",
"product_name": "Insant Noodles",
"per": "6",
"unit": "g",
"status": "y",
"brand": null,
"price": "141.00-229.00",
"stocks": "499",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "97",
"seller_id": "2",
"store_name": "Fresh Menu",
"image": "e8e37e93a78fe3b399ed22d740f36e26.jpg",
"type": "product",
"category_id": "80",
"product_name": "Instant noodles yummy",
"per": "7",
"unit": "g",
"status": "y",
"brand": null,
"price": "310.00-632.00",
"stocks": "499",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
}
]
},
{
"banner": {
"title": "Chocolates",
"banner_img": "https://hapdel.com/assets/uploads/f10ef33b8a6228f0c60e526ebbcbbcce.jpg",
"category_id": "72",
"product_category_id": "86"
},
"items": [
{
"pid": "110",
"seller_id": "2",
"store_name": "Fresh Menu",
"image": "b6f28f0164a1f1fdd243bdfe13df19aa.png",
"type": "product",
"category_id": "86",
"product_name": "Dairy milk chocolate",
"per": "8",
"unit": "g",
"status": "y",
"brand": null,
"price": "102.00-347.00",
"stocks": "499",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "111",
"seller_id": "2",
"store_name": "Fresh Menu",
"image": "a1044f6b7892564e33e72df6a6d08fed.jpg",
"type": "product",
"category_id": "86",
"product_name": "5 star",
"per": "6",
"unit": "g",
"status": "y",
"brand": null,
"price": "455.00-934.00",
"stocks": "496",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "112",
"seller_id": "2",
"store_name": "Fresh Menu",
"image": "587b990f756057946ca5ad4c1c94f5b3.jpg",
"type": "product",
"category_id": "86",
"product_name": "Kitkat",
"per": "7",
"unit": "g",
"status": "y",
"brand": null,
"price": "870.00-979.00",
"stocks": "500",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
}
]
},
{
"banner": {
"title": "Caps Ballons",
"banner_img": "https://hapdel.com/assets/uploads/a36bd4894b7945b3c4e0e45440c43f47.jpg",
"category_id": "134",
"product_category_id": "138"
},
"items": [
{
"pid": "189",
"seller_id": "2",
"store_name": "Fresh Menu",
"image": "c8a7ff1cbedf91e705ca869c9273f70a.jpg",
"type": "product",
"category_id": "138",
"product_name": "Party Caps",
"per": "6",
"unit": "piece",
"status": "y",
"brand": null,
"price": "185.00-479.00",
"stocks": "500",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "190",
"seller_id": "2",
"store_name": "Fresh Menu",
"image": "7b53910622fac5ba343ed6f995961469.jpg",
"type": "product",
"category_id": "138",
"product_name": "Party Ballons",
"per": "6",
"unit": "piece",
"status": "y",
"brand": null,
"price": "613.00-739.00",
"stocks": "500",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "191",
"seller_id": "2",
"store_name": "Fresh Menu",
"image": "3f45e1be5b986398666306c2ed555bab.jpg",
"type": "product",
"category_id": "138",
"product_name": "Party Candels",
"per": "6",
"unit": "piece",
"status": "y",
"brand": null,
"price": "168.00-546.00",
"stocks": "500",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
}
]
},
{
"banner": {
"title": "Kitchen Cleaning",
"banner_img": "https://hapdel.com/assets/uploads/c3c47befb86a95f90b34e85d67339558.jpg",
"category_id": "195",
"product_category_id": "197"
},
"items": [
{
"pid": "269",
"seller_id": "55",
"store_name": "Happy Store",
"image": "9bebd507b222497ca94ace717683f415.jpg",
"type": "service",
"category_id": "197",
"product_name": "Kitchen Cleaner with Chimney",
"per": "3",
"unit": "piece",
"status": "y",
"brand": null,
"price": "52.00-411.00",
"stocks": "0",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "270",
"seller_id": "55",
"store_name": "Happy Store",
"image": "684e9d9254109d096a24f1fa49ff8e2f.jpg",
"type": "service",
"category_id": "197",
"product_name": "Kitchen Cleaning Without Chimney ",
"per": "4",
"unit": "piece",
"status": "y",
"brand": null,
"price": "205.00-634.00",
"stocks": "0",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "272",
"seller_id": "55",
"store_name": "Happy Store",
"image": "7579fb3d47f8b4fa67c4e5600cbe2bc6.jpg",
"type": "service",
"category_id": "197",
"product_name": "Kitchen Trolly and Shelf Cleaning",
"per": "3",
"unit": "piece",
"status": "y",
"brand": null,
"price": "300.00-913.00",
"stocks": "0",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "273",
"seller_id": "55",
"store_name": "Happy Store",
"image": "3caeab50226053e1392f951348f837cc.jpg",
"type": "service",
"category_id": "197",
"product_name": "Kitchen deep Cleaning",
"per": "7",
"unit": "piece",
"status": "y",
"brand": null,
"price": "236.00-937.00",
"stocks": "0",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
}
]
},
{
"banner": {
"title": "AC Service",
"banner_img": "https://hapdel.com/assets/uploads/3cc9c9053a2d5a8907eb88ecbba9967c.jpg",
"category_id": "241",
"product_category_id": "249"
},
"items": [
{
"pid": "288",
"seller_id": "55",
"store_name": "Happy Store",
"image": "bf009db960495c3b431e305a80167726.jpg",
"type": "service",
"category_id": "249",
"product_name": "Window AC",
"per": "7",
"unit": "piece",
"status": "y",
"brand": null,
"price": "334.00-862.00",
"stocks": "0",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
},
{
"pid": "289",
"seller_id": "55",
"store_name": "Happy Store",
"image": "2ccf78dee8ea40d32881491d60535b49.jpg",
"type": "service",
"category_id": "249",
"product_name": "Split AC",
"per": "7",
"unit": "piece",
"status": "y",
"brand": null,
"price": "626.00-830.00",
"stocks": "0",
"short_description": "",
"base_url": "https://hapdel.com/assets/uploads/"
}
]
}
]
}