可扩展的回收器视图和下面的文本视图



我正在尝试用2个标题来实现2个可扩展的回收道。1。2。3。4。由于我的recyclerview是可扩展的,并且当我扩展第一回收瓶时,它将进入我的第二个文本视图内。即我的回收器视图有一个单独的滚动。

我希望第二个文本视图和recyclerview在扩展第一循环时向下移动。

activity.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginBottom="10dp"
    tools:context=".ListActivity">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="22sp"
        android:text="Weightage: 40%"/>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fafafa" />
</LinearLayout>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="22sp"
        android:layout_marginBottom="10dp"
        android:text="Weightage: 60%"/>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recview2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fafafa" />
</LinearLayout>
</ScrollView>

第二个回收瓶也是如此。在扩展第二个回收器视图时,循环系统项目具有单独的滚动,上面的文字停留在一个地方。整体滚动不起作用。

您只能使用一个recyclerview实现此目标。将一个名为"模型"的模型类"模型",其中添加一个诸如" Isheader"之类的变量。当您准备数据列表以在Recyclerview中显示2个模型对象'isheader = true'

另外,制作两个(item_layout.xml&amp; header_layout.xml)xml文件,一个用于header&amp;另一个针对您的原始数据项。

和Recyclerview Adapter类中,您有两个单独的视图持有人类,用于上述每个布局。有关更多详细信息和示例

,请参阅此信息。

public class MultiViewTypeAdapter extends RecyclerView.Adapter {
    public static final int HEADER_VIEW = 0;
    public static final int LIST_VIEW = 1;
    private Resources resources;
    private DownloadListener downloadListener;
    public MyToursAdapter(List<Model> objects) {
        super(objects);
        resources = App.getApp().getResources();
    }
    @NonNull
    @Override
    public RecycleView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == HEADER_VIEW) {
            return new SectionHeaderItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.header_layout, parent, false));
        } else
            return new ListItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, parent, false));
    }
    @Override
    public void onBindViewHolder(@NonNull BaseRecycleAdapter.ViewHolder holder, int position) {
        if (getItemViewType(position) == HEADER_VIEW)
            ((HeaderItemViewHolder) holder).bindHeaderViewHolder(objects.get(position));
        else
            ((ListItemViewHolder) holder).bindListViewHolder(objects.get(position));
    }
    @Override
    public int getItemViewType(int position) {
        if (objects.get(position).isHeader())
            return HEADER_VIEW;
        else
            return LIST_VIEW;
    }
  public class ListItemViewHolder extends BaseRecycleAdapter.ViewHolder {
     //write code to show data from list object.
  }
  public class HeaderItemViewHolder extends BaseRecycleAdapter.ViewHolder {
     //write code to show data from list object.
  }
}

enter code here

最新更新