【问题标题】:Recycler view item is gets truncated回收站视图项目被截断
【发布时间】:2020-11-22 21:07:20
【问题描述】:

我在回收站视图项目中遇到了一种奇怪的行为。 textviews 应该与父母匹配,但是当我运行它时,我得到以下内容

如您所见,所有项目都被截断,尽管它的父项(外部蓝色框)是匹配父项。

如果我向下或向上滚动,则项目会按预期占据空间。请参阅下面我上下滚动的第一项:

有趣的是,在上面最后一张图片之后,如果我弹出键盘备份(或隐藏)它,那么所有项目都会被截断回第一张图片。

回收器视图、键盘和对话框之间的某些东西导致了问题

家长:

    <LinearLayout
            android:id="@+id/llSearch"     
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        
.
.
.
.

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvLocSearch"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_marginTop="8dp" />
    
        </LinearLayout>

项目:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@color/main_light_grey"
    android:paddingTop="5dp"
    android:paddingBottom="5dp">
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        />
    <TextView
        android:id="@+id/tvLine1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="line 1"
        android:textStyle="bold"
        android:textColor="@color/White"
        android:textSize="@dimen/_16ssp" />

    <TextView
        android:id="@+id/tvLine2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="line 2"
        android:textStyle="bold"
        android:textColor="@color/White"
        android:textSize="@dimen/_16ssp" />

    <TextView
        android:id="@+id/tvDistance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="# km"
        android:textColor="@color/White"
        android:textSize="@dimen/_12ssp"
        app:layout_constraintStart_toStartOf="@+id/ivIcon"
        app:layout_constraintTop_toBottomOf="@+id/ivIcon" />



</LinearLayout>

【问题讨论】:

  • 对于键盘问题,可能是android:configChanges="keyboardHidden|screenSize|keyboard"在manifest,activity部分可以理解
  • 谢谢。我尝试过这个。没有运气
  • tvDistance 宽度是wrap_content,再加上什么是ivIcon?你能给我们发一张相关的图片吗,比如我看到文字是“第 2 行”,但在图片中我看不到“第 2 行”。比较容易找到问题所在
  • tvDistance 不是问题。 tvLine1 和 tvLine2 是被截断的

标签: android android-layout android-recyclerview


【解决方案1】:

您需要将 tvDistance 的宽度与其他小部件保持匹配父级。

替换这一行

  android:id="@+id/tvDistance"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"

这个

 android:id="@+id/tvDistance"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"

【讨论】:

  • tvLine1 是匹配父级。设置距离以匹配父级或包装内容应该有效果
  • 是的,会有的。尝试更改并检查结果。
猜你喜欢
  • 1970-01-01
  • 2022-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-11
  • 2015-07-16
  • 2020-11-02
相关资源
最近更新 更多