【问题标题】:RecyclerView random acts of paddingRecyclerView 随机填充行为
【发布时间】:2017-03-12 05:35:48
【问题描述】:

我正在尝试按照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>

【问题讨论】:

  • 分享你的适配器代码
  • 请把你的行布局xml
  • 当然,我编辑了帖子

标签: android android-recyclerview padding


【解决方案1】:

尝试将父行布局的高度更改为 wrap_content 或固定 dpi。

由于此更改,请务必仔细检查项目视图的布局参数:以前忽略的布局参数(例如滚动方向中的 MATCH_PARENT)现在将得到完全尊重。

Source

<?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>

【讨论】:

  • @MarkPrice 如果您认为这是正确答案,请点赞并批准我的回答,谢谢。
猜你喜欢
  • 1970-01-01
  • 2017-06-04
  • 1970-01-01
  • 1970-01-01
  • 2018-12-08
  • 1970-01-01
  • 2016-07-22
  • 2012-12-11
  • 1970-01-01
相关资源
最近更新 更多