Android:滚动时,Recyclerview中的水平线视图闪烁

时间:2018-07-23 15:42:33

标签: android android-layout android-recyclerview recyclerview-layout

我在Recyclerview项目中遇到问题  当滚动线闪烁时,它包含多条视图作为水平线,我不知道为什么。

this视频解释了这个问题。

这是Recyclerviewitem.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:id="@+id/new_post_list_item_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    >

    <android.support.constraint.ConstraintLayout
        android:id="@+id/new_post_upper_part_container"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_marginTop="8dp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/new_post_upper_user_image_view"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="16dp"
            app:layout_constraintStart_toStartOf="parent" />

        <ImageView
            android:id="@+id/new_post_upper_activity_icon"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_marginStart="50dp"
            android:layout_marginTop="30dp"
            android:src="@drawable/comment_notification"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/new_post_upper_text_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="16dp"
            android:text="Abdulmalek Dery and two other commented Rami Issa post"
            android:textColor="@color/black"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/new_post_upper_user_image_view"

            />
    </android.support.constraint.ConstraintLayout>

    <View
        android:id="@+id/new_post_upper_line_divider"
        android:layout_width="match_parent"
        android:layout_height="0.3dp"
        android:background="#BDBDBD"
        app:layout_constraintTop_toBottomOf="@+id/new_post_upper_part_container" />

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/new_post_poster_image_circle_image_view"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:src="@color/colorListDivider"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/new_post_upper_part_container" />

    <TextView
        android:id="@+id/new_post_user_name_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:text="Rami issa"
        android:textColor="@color/black"
        android:textSize="16sp"
        android:textStyle="bold"
        app:layout_constraintStart_toEndOf="@+id/new_post_poster_image_circle_image_view"
        app:layout_constraintTop_toBottomOf="@+id/new_post_upper_part_container" />

    <com.github.curioustechizen.ago.RelativeTimeTextView
        android:id="@+id/new_post_date_relative_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:text="3 m"
        app:layout_constraintStart_toEndOf="@+id/new_post_poster_image_circle_image_view"
        app:layout_constraintTop_toBottomOf="@+id/new_post_user_name_text_view" />

    <ImageView
        android:id="@+id/new_post_option_image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="16dp"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/new_post_upper_part_container"
        app:srcCompat="@drawable/post_options_icon" />

    <TextView
        android:id="@+id/new_post_image_description_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:paddingEnd="16dp"
        android:paddingStart="16dp"
        android:text="nice image right?"
        android:textColor="@color/black"
        android:textSize="14sp"
        android:visibility="visible"
        app:layout_constraintTop_toBottomOf="@+id/new_post_poster_image_circle_image_view" />
<LinearLayout
    android:id="@+id/linear_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintTop_toBottomOf="@+id/new_post_image_description_text_view">
    <ImageView
        android:id="@+id/new_post_image_view"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:visibility="visible"
        android:src="@color/colorListDivider"/>

    <me.grantland.widget.AutofitTextView
        android:id="@+id/new_post_content_auto_fit_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:ellipsize="end"
        android:maxLines="3"
        android:paddingEnd="16dp"
        android:paddingStart="16dp"
        android:text="some post content  that activity like that work"
        android:textColor="@color/black"
        android:textSize="40sp"
        android:visibility="gone"
        app:layout_constraintTop_toBottomOf="@+id/new_post_poster_image_circle_image_view"
        app:minTextSize="16sp" />
</LinearLayout>
    <View
        android:id="@+id/new_post_lower_line_view"
        android:layout_width="match_parent"
        android:layout_height="0.8dp"
        android:layout_marginTop="8dp"
        android:background="#BDBDBD"
        android:visibility="visible"
        app:layout_constraintTop_toBottomOf="@+id/linear_view" />

    <ImageView
        android:id="@+id/new_post_react_gray_image_view"
        android:layout_width="@dimen/post_icons_dimen"
        android:layout_height="@dimen/post_icons_dimen"
        android:layout_centerVertical="true"
        android:layout_marginStart="16dp"
        android:layout_marginTop="6dp"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        android:visibility="visible"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/new_post_lower_line_view" />

    <ImageView
        android:id="@+id/new_post_react_red_image_view"
        android:layout_width="@dimen/post_icons_dimen"
        android:layout_height="@dimen/post_icons_dimen"
        android:layout_centerVertical="true"
        android:layout_marginStart="16dp"
        android:layout_marginTop="6dp"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        android:src="@mipmap/love_gray_icon"
        android:visibility="visible"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/new_post_lower_line_view" />

    <ImageView
        android:id="@+id/new_post_comment_image_view"
        android:layout_width="@dimen/post_icons_dimen"
        android:layout_height="@dimen/post_icons_dimen"
        android:layout_centerVertical="true"
        android:layout_marginStart="12dp"
        android:layout_marginTop="6dp"
        android:layout_toEndOf="@+id/new_post_react_gray_image_view"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        android:src="@mipmap/comment_icon"
        app:layout_constraintStart_toEndOf="@+id/new_post_react_gray_image_view"
        app:layout_constraintTop_toBottomOf="@+id/new_post_lower_line_view" />
    />

    <ImageView
        android:id="@+id/new_post_share_image_view"
        android:layout_width="@dimen/post_icons_dimen"
        android:layout_height="@dimen/post_icons_dimen"
        android:layout_centerVertical="true"
        android:layout_marginStart="12dp"
        android:layout_marginTop="6dp"
        android:layout_toEndOf="@+id/new_post_comment_image_view"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        android:src="@mipmap/share_icon"
        app:layout_constraintStart_toEndOf="@+id/new_post_comment_image_view"
        app:layout_constraintTop_toBottomOf="@+id/new_post_lower_line_view" />

    <ImageView
        android:id="@+id/new_post_send_message_image_view"
        android:layout_width="@dimen/post_icons_dimen"
        android:layout_height="@dimen/post_icons_dimen"
        android:layout_centerVertical="true"
        android:layout_marginStart="12dp"
        android:layout_marginTop="6dp"
        android:layout_toEndOf="@+id/new_post_share_image_view"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        app:layout_constraintStart_toEndOf="@+id/new_post_share_image_view"
        app:layout_constraintTop_toBottomOf="@+id/new_post_lower_line_view" />


    <TextView
        android:id="@+id/new_post_engagements_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="6dp"
        android:clickable="true"
        android:text="@string/post_engagements"
        android:textSize="14sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/new_post_lower_line_view" />

    <TextView
        android:id="@+id/new_post_engagements_count_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginEnd="4dp"
        android:layout_marginTop="6dp"
        android:text="20"
        android:textSize="14sp"
        app:layout_constraintEnd_toStartOf="@+id/new_post_engagements_text_view"
        app:layout_constraintTop_toBottomOf="@+id/new_post_lower_line_view" />

    <View
        android:id="@+id/new_post_under_reacts_line_view"
        android:layout_width="match_parent"
        android:layout_height="0.1dp"
        android:layout_marginTop="6dp"
        android:background="#BDBDBD"
        app:layout_constraintTop_toBottomOf="@+id/new_post_send_message_image_view" />

    <android.support.constraint.ConstraintLayout
        android:id="@+id/new_post_comment_view_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#eceff1"
        android:paddingBottom="12dp"
        android:paddingStart="16dp"
        android:paddingTop="12dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/new_post_under_reacts_line_view">


        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/new_post_user_image_in_comments_circle_image_view"
            android:layout_width="42dp"
            android:layout_height="42dp"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:clickable="true"
            android:focusable="true" />

        <TextView
            android:id="@+id/new_post_user_name_in_comments_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:text="Abdulmalek Dery"
            android:textColor="@color/black"
            android:textSize="14sp"
            android:textStyle="bold"
            app:layout_constraintStart_toEndOf="@+id/new_post_user_image_in_comments_circle_image_view" />

        <com.github.curioustechizen.ago.RelativeTimeTextView
            android:id="@+id/new_post_comment_date_relative_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:text="2 hour ago"
            android:textSize="12sp"
            app:layout_constraintStart_toEndOf="@+id/new_post_user_image_in_comments_circle_image_view"
            app:layout_constraintTop_toBottomOf="@+id/new_post_user_name_in_comments_text_view" />

        <TextView
            android:id="@+id/new_post_comment_content_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:ellipsize="end"
            android:maxLines="3"
            android:text="some comment on this nice pic"
            android:textColor="@color/black"
            android:textSize="14sp"
            app:layout_constraintStart_toEndOf="@+id/new_post_user_image_in_comments_circle_image_view"
            app:layout_constraintTop_toBottomOf="@+id/new_post_comment_date_relative_text_view" />
    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

和问题也我已经测试了三星A5上的应用程序,它不显示任何闪烁,但在华为设备中显示闪烁。 有帮助吗?

1 个答案:

答案 0 :(得分:1)

不建议使用android:layout_height,其值应低至0.1dp,具体取决于设备的屏幕密度和视图位置,此值可以向下舍入到1个像素以下,这会导致视图消失。

如果您想拥有非常细的线条,可以使用像1px这样的直接像素高度而不是dp,那样可伸缩性较差,但应防止闪烁。