CardView中的RecyclerView Adapter显示问题

时间:2018-10-10 19:07:38

标签: java android firebase android-recyclerview recycler-adapter

我已经制作了一个CardView中的RecyclerView适配器,如下图所示。卡片具有隐藏的布局,单击后即可看到。

enter image description here

enter image description here

我遇到一个问题,当我有许多数据集作为卡,并扩展一个或多个卡时,某些卡会变得异常且无限期地不可见。当前屏幕中未显示的卡似乎面临此问题。

enter image description here \

enter image description here

当我滚动浏览卡片时,视图变得更加复杂,一些卡片变得越来越小,并且在内容相同的情况下它们之间留有空白。

请任何人帮助我解决问题。

编辑:这是我的布局文件:

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>

0 个答案:

没有答案