View Recycle上的CardView大小问题

时间:2018-10-21 18:48:42

标签: android android-recyclerview cardview

我创建了一个recyclerview适配器类,其项目布局包含一个cardview,里面有一些textview和imageviews。我面临的问题是,在回收视图时,我的cardview大小会发生变化,并且会隐藏另一个cardview的内容。

我认为问题是因为每个项目的卡片高度不同。因此,当物品被回收时,它将占用另一张卡片的高度,这是不同的。如何解决这个问题?请帮忙。

问题的视频链接:https://drive.google.com/file/d/1nlgq-eQ-rhRNadOyzg4FwjVzrIk88Ve8/view?usp=sharing

open_up_list_view.xml

 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

<RelativeLayout 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.support.v7.widget.CardView
    android:id="@+id/openUpCardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/nav_header_vertical_spacing"
    android:layout_marginEnd="@dimen/dimen_16x"
    android:layout_marginLeft="@dimen/activity_vertical_margin"
    android:layout_marginRight="@dimen/dimen_16x"
    android:layout_marginStart="@dimen/activity_vertical_margin"
    android:layout_marginTop="@dimen/dimen_4x"
    android:clickable="true"
    android:focusable="true"
    app:cardCornerRadius="@dimen/dimen_8x">

    <RelativeLayout
        android:id="@+id/openUpRelativeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/dimen_8x"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <ProgressBar
                        android:id="@+id/openUpAuthorImageProgress"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent" />

                    <de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/openUpAuthorImage"
                        android:layout_width="@dimen/dimen_48x"
                        android:layout_height="@dimen/dimen_48x"
                        android:layout_marginBottom="@dimen/dimen_4x"
                        android:layout_marginLeft="@dimen/dimen_4x"
                        android:layout_marginRight="@dimen/dimen_4x"
                        android:layout_marginTop="@dimen/dimen_4x"

                        app:civ_border_color="#FF000000"
                        app:civ_border_width="2dp" />
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:id="@+id/openUpAuthorName"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/cardview_default_radius"
                        android:layout_marginLeft="@dimen/dimen_8x"
                        android:layout_marginRight="@dimen/dimen_8x"
                        android:layout_marginTop="@dimen/dimen_8x"
                        android:text="loading.."
                        android:textColor="@color/colorPrimaryDark"
                        android:textSize="@dimen/dimen_16x"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/openUpDate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/openUpAuthorName"
                        android:layout_marginLeft="@dimen/dimen_8x"
                        android:textSize="@dimen/dimen_12x" />
                </RelativeLayout>


            </LinearLayout>

            <TextView
                android:id="@+id/openUpTextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_gravity="left"
                android:autoLink="web"
                android:padding="@dimen/dimen_4x"
                android:textAlignment="textStart"
                android:textColor="@color/cardview_dark_background"
                android:textSize="@dimen/dimen_16x" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ProgressBar
                    android:id="@+id/openUpImageProgress"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />

                <com.github.chrisbanes.photoview.PhotoView
                    android:id="@+id/openUpImageView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/dimen_8x"
                    android:layout_marginLeft="@dimen/dimen_4x"
                    android:layout_marginRight="@dimen/dimen_4x"
                    android:layout_marginTop="@dimen/dimen_8x"
                    android:layout_weight="1"
                    app:srcCompat="@drawable/common_google_signin_btn_icon_dark" />


            </RelativeLayout>


            <View
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@android:color/darker_gray"
                android:hapticFeedbackEnabled="false"></View>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <CheckBox
                    android:id="@+id/openUpLikeIcon"
                    android:layout_width="@dimen/dimen_32x"
                    android:layout_height="@dimen/dimen_24x"
                    android:layout_marginBottom="@dimen/dimen_4x"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="8dp"
                    android:background="@drawable/thumb_off"
                    android:button="@null"
                    android:checked="false"
                    android:clickable="true"
                    android:focusable="true"
                    android:stateListAnimator="@animator/scale"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/image" />

                <TextView
                    android:id="@+id/openUpLikeTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/nav_header_vertical_spacing"
                    android:layout_marginTop="@dimen/dimen_8x"

                    android:text="loading.."
                    android:textSize="@dimen/dimen_16x" />

                <ImageView
                    android:id="@+id/openUpCommentIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/fab_margin"
                    android:layout_marginTop="@dimen/dimen_8x"
                    app:srcCompat="@drawable/comment_icon" />

                <TextView
                    android:id="@+id/openUpCommentTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/dimen_8x"

                    android:text="loading.."
                    android:textSize="@dimen/dimen_16x" />


                <TextView
                    android:id="@+id/openUpDeleteText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/dimen_4x"
                    android:layout_marginTop="@dimen/dimen_8x"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:text="Delete"
                    android:textSize="@dimen/dimen_16x" />

            </LinearLayout>

            <View
                android:id="@+id/commentSeparatorView"
                android:layout_width="match_parent"
                android:layout_height="1.5dp"

                android:layout_marginTop="@dimen/nav_header_vertical_spacing"
                android:background="@color/colorPrimaryDark"
                android:hapticFeedbackEnabled="false"></View>

            <TextView
                android:id="@+id/commentSeparatorText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="@dimen/dimen_8x"
                android:gravity="center"
                android:text="Comments"
                android:textColor="@color/common_google_signin_btn_text_dark_focused" />

            <LinearLayout
                android:id="@+id/commentsLL"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="@dimen/dimen_4x"
                android:background="@null"
                android:orientation="vertical">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/commentsRecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">


                </android.support.v7.widget.RecyclerView>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal">

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:hint="Add a comment..">

                        <android.support.design.widget.TextInputEditText
                            android:id="@+id/commentEditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />
                    </android.support.design.widget.TextInputLayout>

                    <android.support.v7.widget.AppCompatButton
                        android:id="@+id/commentPostButton"
                        android:layout_width="80dp"
                        android:layout_height="wrap_content"
                        android:backgroundTint="@color/colorPrimaryDark"
                        android:text="POST"
                        android:textColor="@color/cardview_light_background" />

                </LinearLayout>

            </LinearLayout>
        </LinearLayout>


    </RelativeLayout>
</android.support.v7.widget.CardView>

</RelativeLayout>
</ScrollView>

编辑:RecyclerView布局

fragment_open_up.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bittentech.localvariable.fragments.OpenUpFragment">

<!-- TODO: Update blank fragment layout -->

<TextView
    android:id="@+id/openUpEmptyView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:gravity="center_vertical|center_horizontal"
    android:text="All caught up!!" />
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/openUpSwipeRefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <android.support.v7.widget.RecyclerView
        android:id="@+id/openUpRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="false"/>




</android.support.v4.widget.SwipeRefreshLayout>

</FrameLayout>

0 个答案:

没有答案