androidfirebasetextviewexpandable

How to expand textView and automatically the next fields will be moved?


I am retrieving the large content from firebase in that text view but i want to show only 3 lines and after that i want to show "readmore/showmore" option and when use clicks on that full content will show and next fields will automatically shift downwards like using scrollview! My information is overlapping the next fields,can anyone help?

<?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"
    xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
    tools:context=".MoreDetails">

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

        <ImageView
            android:id="@+id/cropimage"
            android:layout_width="265dp"
            android:layout_height="265dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:contentDescription="TODO"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="300dp"
            android:text="Description :"
            android:textSize="20sp"
            android:autoSizeTextType="uniform"
            android:autoSizeMinTextSize="12sp"
            android:autoSizeMaxTextSize="20sp"/>

<com.borjabravo.readmoretextview.ReadMoreTextView
            android:id="@+id/description_info"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="330dp"
            android:textSize="15sp"
            app:trimCollapsedText="@string/read_more"
            app:trimExpandedText="@string/read_less"
            app:trimMode="trimModeLength"
            app:trimLength="180"
            app:colorClickableText="#000"/>

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="100"
            android:paddingTop="430dp">

            <TextView
                android:id="@+id/planting_time"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:text="planting time :"
                android:gravity="center"
                android:textSize="20sp"
                android:layout_weight="60" />

            <TextView
                android:id="@+id/planting_time_info"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:autoSizeTextType="uniform"
                android:autoSizeMinTextSize="12sp"
                android:autoSizeMaxTextSize="20sp"
                android:maxLines="16"
                android:layout_weight="40"/>

        </LinearLayout>

            <View
                android:layout_width="wrap_content"
                android:layout_height="2dp"
                android:background="@color/colorPrimary"
                android:layout_marginTop="420dp"/>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="100"
            android:paddingTop="530dp">

            <TextView
                android:id="@+id/bloom_time"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:text="bloom time :"
                android:gravity="center"
                android:textSize="20sp"
                android:layout_weight="60" />

            <TextView
                android:id="@+id/bloom_time_info"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:autoSizeTextType="uniform"
                android:autoSizeMinTextSize="12sp"
                android:autoSizeMaxTextSize="20sp"
                android:maxLines="16"
                android:layout_weight="40"/>

        </LinearLayout>

        <View
            android:layout_width="wrap_content"
            android:layout_height="2dp"
            android:background="@color/colorPrimary"
            android:layout_marginTop="530dp"/>


Solution

  • Like description have maxLines=3

     <TextView
                android:id="@+id/description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="300dp"
                android:text="Description :"
                android:textSize="20sp"
                android:maxLines="3"
                android:autoSizeTextType="uniform"
                android:autoSizeMinTextSize="12sp"
                android:autoSizeMaxTextSize="20sp"/>
    

    Now you want to make lines upto text lines after click then do this in java

    description.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    description.setLines(description.getLineCount());
                }
            });
    

    Hope it will work

    Thankew! Happy coding!