Recyclerview体系结构如何处理嵌套适配器



android recyclerview如何处理嵌套视图,我有一个适配器json复杂,但图像多个时间重复

"id": "c200",
            "name": "Ravi Tamada",
            "email": "ravi@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": [{
                "image": "image.png",
                "image": "image.png",
                "image": "image.png"
            }}
            }

如何显示图像

在此处输入图像描述

您有两个选择。

  1. 您可以在卡中使用线安排,并夸大包含imageView的自定义layout
  2. 您可以在卡中使用Recyclerview。

解释选项2 -

您可以在现有的循环范围内使用另一个回收道。

cardView-

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView  
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ViewAllLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
android:paddingBottom="8dp">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
.
.
.
.
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="4dp"
    android:paddingRight="4dp"
    android:paddingTop="4dp"/>
.
.
.
</LinearLayout>
</android.support.v7.widget.CardView>

父母回收库的视图持有人将更改为这样的东西。

    class MyViewHolder2 extends RecyclerView.ViewHolder {
    RecyclerView recyclerView;
    MyHorizontalAdapter horizontalAdapter;
......//rest of objects
.....
    public MyViewHolder2(View itemView) {
        super(itemView);
        recyclerView = (RecyclerView) itemView.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        horizontalAdapter = new MyHorizontalAdapter(context);
        recyclerView.setAdapter(horizontalAdapter);
        recyclerView.setNestedScrollingEnabled(false);
        .....//rest of initialization codes
        .....
        .....
    }
    public void bind(JSONObject object) throws JSONException {
        horizontalAdapter.setHorizontalData(object.getJSONArray("phone"));
        ........//rest of bind data
        .......
        .......
    }

donot忘记线

    recyclerView.setNestedScrollingEnabled(false);

它将水平回收列表放在截距垂直卷轴上。

在水平载体中使用它,就像U普通的Recyclerview适配器一样。由于您正在加载图像,因此可以使用毕加索或滑行等库。

funtion-

public void setHorizontalData(JSONArray data){
....
notifyDataSetChanged();
}

最新更新