Java 使用自定义LinearLayoutManager
我尝试使用此自定义LinearLayoutManager(用于在我的RecyclerView上使用包裹内容): 此外,当我编译时,我的应用程序崩溃,我有以下错误: java.lang.NoSuchMethodError:android.support.v7.widget.RecyclerView$LayoutParams.getViewLayoutPosition 这是我的XML:Java 使用自定义LinearLayoutManager,java,android,android-recyclerview,Java,Android,Android Recyclerview,我尝试使用此自定义LinearLayoutManager(用于在我的RecyclerView上使用包裹内容): 此外,当我编译时,我的应用程序崩溃,我有以下错误: java.lang.NoSuchMethodError:android.support.v7.widget.RecyclerView$LayoutParams.getViewLayoutPosition 这是我的XML: <?xml version="1.0" encoding="utf-8"?> <LinearL
<?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>
提前感谢并祝您愉快:o)添加到您的构建中。gradle
依赖项
:
compile('com.android.support:recyclerview-v7:22.2.0') {
exclude module: 'support-v4'
}
非常感谢,它很有效!只是,为什么我必须排除support-v4?当您将在项目中使用其他库,如
appcompat
,cardview
,最好将support-v4
从它们中排除,因为每个库都会带来自己的版本,如果此库中的support-v4
出现一些问题,并且仍未修复,则会产生问题;最好一次导入compile('com.android.support:support-v4:22.2.+')
,这一个将用于所有库,并从其他库中排除support-v4
,这些库可以提供自己的版本
compile('com.android.support:recyclerview-v7:22.2.0') {
exclude module: 'support-v4'
}