碎片回收视图(带卡)已复制并超额分配

时间:2018-09-15 10:04:33

标签: java android xml

已解决

删除LinearLayoutManager将解决此问题。谢谢!

我正在用2列的Recycle View和Card样式编写一个Android应用程序视图。但奇怪的是,它还有另一个重复的回收视图,分层后没有滚动视图。

请帮助告知:)

enter image description here

编辑: 它在片段内。片段的代码

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View fragmentView = inflater.inflate(R.layout.fragment_discover, container, false);

        recyclerView = (RecyclerView) fragmentView.findViewById(R.id.rv_merchants); 
         recyclerView.setHasFixedSize(true);

        final LinearLayoutManager layoutManager = new LinearLayoutManager(fragmentView.getContext());

        RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(fragmentView.getContext(), 2);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());

        data = new ArrayList<ExampleDataModel>();
        for (int i = 0; i < DA_ExampleDataModel.nameArray.length; i++) {
            data.add(new ExampleDataModel(
                    DA_ExampleDataModel.nameArray[i],
                    DA_ExampleDataModel.versionArray[i],
                    DA_ExampleDataModel.id_[i],
                    DA_ExampleDataModel.drawableArray[i]
            ));
        }

      layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
      adapter = new RV_DiscoveryMerchant(data);

        recyclerView.setAdapter(adapter);

            return fragmentView;  


 }

片段的XML:

<?xml version="1.0" encoding="utf-8"?> <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:paddingBottom="15dp"
    android:paddingLeft="15dp"
    android:paddingRight="0dp"
    android:paddingTop="15dp"
    tools:context=".Fragment.DiscoverFragment"> 

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="Android version"
        android:textAppearance="@style/TextAppearance.AppCompat.Headline"
        android:textSize="30sp" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_merchants"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />


 </LinearLayout>

0 个答案:

没有答案