使用自定义LinearLayoutManager

时间:2015-07-08 08:14:27

标签: java android android-recyclerview

我尝试使用这个自定义LinearLayoutManager(用于在我的RecyclerView上使用wrap内容):

https://github.com/serso/android-linear-layout-manager

此外,当我编译时,我的应用程序崩溃,我有这个错误:

java.lang.NoSuchMethodError:android.support.v7.widget.RecyclerView $ LayoutParams.getViewLayoutPosition

这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="10"
    android:orientation="vertical"
    android:background="@color/hypred_noir">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="4.5"
            android:background="@color/hypred_rouge"
            android:layout_gravity="center_vertical">
            <android.support.v7.widget.RecyclerView
                android:id="@+id/critere_rep_recycler_view_un"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scrollbarStyle="insideOverlay"
                android:overScrollMode="never"
                android:layout_centerInParent="true">
            </android.support.v7.widget.RecyclerView>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
            <View
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:layout_centerVertical="true"
                android:background="@color/hypred_grey"
                android:layout_centerInParent="true"/>
            <com.ylly.hypred.custom.MyTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                custom:font_name="Arial-Bold.ttf"
                android:background="@color/hypred_blanc"
                android:textColor="@color/hypred_gris"
                android:paddingRight="1dp"
                android:paddingLeft="1dp"
                android:text="@string/ou"/>
        </RelativeLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4.5">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/critere_rep_recycler_view_deux"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbarStyle="insideOverlay"
            android:overScrollMode="never"
            android:layout_centerInParent="true">
        </android.support.v7.widget.RecyclerView>
    </LinearLayout>
</LinearLayout>

我的代码:

RecyclerView recyclerViewCritere = (RecyclerView) v.findViewById(R.id.critere_rep_recycler_view_un);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
recyclerViewCritere.setLayoutManager(linearLayoutManager);
recyclerViewCritere.addItemDecoration(new DividerItemDecoration(context, null));

Drawable drawable1 = context.getResources().getDrawable(R.drawable.hypred_critere_decolmatage);
Drawable drawable2 = context.getResources().getDrawable(R.drawable.hypred_critere_fouling_test);
Drawable drawable3 = context.getResources().getDrawable(R.drawable.hypred_critere_biofilm_solutions);
Drawable drawable4 = context.getResources().getDrawable(R.drawable.hypred_critere_eau);
Drawable drawable5 = context.getResources().getDrawable(R.drawable.hypred_critere_approche_audit_hypred);
Drawable drawable6 = context.getResources().getDrawable(R.drawable.hypred_critere_suivi_intallation);

ItemDataCritere itemDataCritere[] = {new ItemDataCritere("Décolmatage", drawable1),
        new ItemDataCritere("Fouling Test", drawable2), new ItemDataCritere("BioFilm Solutions", drawable3),
        new ItemDataCritere("L'Eau", drawable4), new ItemDataCritere("Approche Audit HYPRED", drawable5),
        new ItemDataCritere("Suivi Installation", drawable6)};

recyclerViewCritere.setAdapter(new MyCritereAdapter(itemDataCritere));

提前致谢并度过美好的一天:o)

1 个答案:

答案 0 :(得分:0)

添加到build.gradle depencendies

compile('com.android.support:recyclerview-v7:22.2.0') {
    exclude module: 'support-v4'
}