Search code examples
androidtextviewscrollview

ScrollView cuts last lines in TextView


I have a problem with ScrollView. On very small screen like 480x800 TextView is getting cut by ScrollView, it doesn't scroll to the end. I think it cuts 2-3 last lines and scrollview can't measure full height. On normal screens works well. My code looks like this.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">

<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardCornerRadius="10dp"
    android:layout_margin="5dp">

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

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:scaleType="centerCrop"
            android:id="@+id/image"
            android:src="@drawable/xyz"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:alpha=".5"
            android:layout_above="@id/title"
            android:background="@android:color/darker_gray" />
        <TextView
            android:id="@+id/title"
            android:textColor="#262626"
            android:layout_below="@id/image"
            android:layout_marginTop="10dp"
            android:layout_marginStart="16dp"
            android:text="Title"
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

            <ScrollView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/title"
                android:layout_marginTop="5dp"
                android:layout_gravity="center_vertical">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <TextView
                        android:id="@+id/desc"
                        android:textSize="16sp"
                        android:fontFamily="@font/open_sans"
                        android:layout_marginLeft="16dp"
                        android:layout_marginBottom="16dp"
                        android:layout_marginRight="16dp"
                        android:drawablePadding="10dp"
                        android:ellipsize="end"
                        android:text="Description"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
                </RelativeLayout>
            </ScrollView>
    </RelativeLayout>
</androidx.cardview.widget.CardView>


Solution

  • I found a solution. Just change in RelativeLayout android:layout_height="530dp" to wrap_content and set it to CardView.