RecyclerView 填充的随机行为
RecyclerView random acts of padding
我正在尝试按照 http://www.androidhive.info/2016/01/android-working-with-recycler-view/ 上的教程进行操作
实现一个 recyclerView,到目前为止一切都按计划进行,除了这件事。
滚动并回收元素后,将使用大量填充重新创建它们(如此处所示https://youtu.be/jkGLLRnjtN0)
我不知道为什么会这样,有人能解释一下吗?谢谢
编辑:我的行布局 xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:textColor="#000"
android:textSize="16dp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/year"
android:textColor="#000"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/genre"
android:layout_below="@id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
尝试将父行布局的高度更改为 wrap_content 或固定 dpi。
Due to this change, make sure to double check the layout parameters of your item views: previously ignored layout parameters (such as MATCH_PARENT in the scroll direction) will now be fully respected.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
// your content
</RelativeLayout>
我正在尝试按照 http://www.androidhive.info/2016/01/android-working-with-recycler-view/ 上的教程进行操作 实现一个 recyclerView,到目前为止一切都按计划进行,除了这件事。
滚动并回收元素后,将使用大量填充重新创建它们(如此处所示https://youtu.be/jkGLLRnjtN0)
我不知道为什么会这样,有人能解释一下吗?谢谢
编辑:我的行布局 xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:textColor="#000"
android:textSize="16dp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/year"
android:textColor="#000"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/genre"
android:layout_below="@id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
尝试将父行布局的高度更改为 wrap_content 或固定 dpi。
Due to this change, make sure to double check the layout parameters of your item views: previously ignored layout parameters (such as MATCH_PARENT in the scroll direction) will now be fully respected.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
// your content
</RelativeLayout>