首页 > 解决方案 > 如何通过水平滚动检查卡片内的 TextView 扩展了 recyclerView 中的 cardView 大小?

问题描述

我在我的应用程序中创建了一个阅读器,我使用Cardview来使用Textview显示每个页面上下文。每个 cardView 内都有一个Textview

在这里,我使用具有 CardView 高度为"wrap_content"的水平滚动。

问题

所以,现在的问题是每个页面中的页面内容是动态的。当我显示TextView内容时 - 当内容太大时,一些行在底部被切断,如下图所示 -

在此处输入图像描述

我想在下一张卡片中显示,其中没有线被切断,如下所示 -

在此处输入图像描述

下面是每个布局项的代码 -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    android:layout_marginBottom="5dp"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

            <android.support.v7.widget.CardView
                xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:id="@+id/card_view_left"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                card_view:cardCornerRadius="5dp"
                card_view:contentPadding="10dp"
                card_view:cardBackgroundColor="@color/colorTransparent"
                card_view:cardElevation="4dp"
                card_view:cardMaxElevation="5dp"
                android:layout_marginBottom="12dp"
                android:layout_marginRight="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="-7dp"
                >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"

                    android:orientation="vertical"
                    >

                <TextView
                    android:id="@+id/tvPageNo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"

                    android:layout_gravity="right"
                    android:text=""
                    android:layout_marginRight="20dp"
                    android:visibility="gone"

                    />

                <com.actinarium.aligned.TextView
                    android:layout_marginStart="10dp"
                    android:layout_marginEnd="10dp"
                    android:id="@+id/tv_content"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"

                    android:textAppearance="@style/TextAppearance.AppCompat.Body1"
                    android:textSize="14sp"

                    app:leading="16sp"
                    app:firstLineLeading="24sp"

                    android:layout_marginBottom="10dp"

                    />


                </LinearLayout>


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

        <View
            android:id="@+id/viewPageUnderLine"
            android:layout_width="fill_parent"
            android:layout_height="2dp"
            android:background="#c0c0c0"

            android:layout_marginTop="10dp"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:visibility="gone"
            />

    </LinearLayout>


    <com.wang.avi.AVLoadingIndicatorView
        android:id="@+id/loading_indicator"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:indicatorName="LineScaleIndicator"
        app:indicatorColor="@color/colorOrange"

        />

</RelativeLayout>

标签: javaandroidxmltextviewcardview

解决方案


最好的方法是设置 android:maxLines="10" 和 android:minLines="10"。父卡片视图应该具有与文本视图匹配的高度。如果要截断任何文本,则将截断的文本放入同样遵循上述规则的下一个卡片视图中。


推荐阅读