Android-ExpandableTextView icon indicating copy to clipboard operation
Android-ExpandableTextView copied to clipboard

Expands once but won't collapse

Open Michael1009 opened this issue 7 years ago • 7 comments

Hello,

My issue is that the button to expand the text only works on the first try. When I load the screen, I can expand the text correctly. However, when I try to collapse it, it looks like it's collapsing but then it expands again and then the button does not collapse or expand anything anymore. Running debug I can see that it is running collapse() method... It just is not correctly collapsing.

start

Expands fine here

expand

Starts to collapse but gets about halfway before expanding again. Does not work after this

failedcollapse

Michael1009 avatar Aug 12 '16 14:08 Michael1009

Hi Michael

thanks for reporting this issue!

Can you provide me your layout file and a code snippet from your Fragment / Activity? I'll try to reproduce the issue on my side and help you out asap.

Thanks again! Cliff

Cliffus avatar Aug 13 '16 10:08 Cliffus

Hi Michael

did you already find some time to check my previous questions to you?

Thanks! Cliff

Cliffus avatar Aug 21 '16 11:08 Cliffus

I have set max lines 4. On first load I have 4 lines. I click on the text, it expands. Than I click to collapse, it collapses to 4 and than expands back. Than if I click again nothing happens. Text stays expanded. expandText.setInterpolator(new OvershootInterpolator()); expandText.setMaxLines(4); expandText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(expandText.isExpanded()){ expandText.collapse(); } else{ expandText.expand(); } } });

Layout is a bit stripped down.. `<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"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="8dp" android:orientation="vertical">

        <TextView
            android:id="@+id/anchor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:minHeight="?attr/actionBarSize"/>

        <android.support.percent.PercentRelativeLayout
            android:id="@+id/detailWrapper"
            android:layout_below="@+id/anchor"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="20dp">

            <RelativeLayout
                android:id="@+id/detailContainer"
                android:layout_alignParentLeft="true"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_widthPercent="95%">

                <LinearLayout
                    android:id="@+id/sponsorLogoContainer"
                    ...
                </LinearLayout>

                ...

                <TextView
                    android:id="@+id/title"
                    android:layout_below="@id/thumbnail"
                    .../>

                <TextView
                    android:id="@+id/episodeIndex"
                    android:layout_below="@id/title"
                    .../>

                <at.blogc.android.views.ExpandableTextView
                    android:id="@+id/subtitle"
                    android:layout_below="@id/episodeIndex"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="0dp"
                    android:layout_marginTop="@dimen/detail_title_margin"
                    android:layout_marginRight="@dimen/detail_title_margin_right"
                    android:text="Subtitle text"
                    android:textSize="@dimen/detail_subtitle_size" />

                <LinearLayout
                    android:id="@+id/buttonsWrapper"
                    android:layout_below="@id/subtitle"
                    ...
                </LinearLayout>

                ...
                </RelativeLayout>


        </android.support.percent.PercentRelativeLayout>
    </RelativeLayout>

</RelativeLayout>`

How ever, I used a different approach at the end and I don't have the orig element, but this is the fragment layout where I used the ExpandableTextView. Now I is just a simple TextView, just renamned that one so you can see where it was originally. Same thing happen to me as mentioned above. Hope it helps...

parohy avatar Oct 14 '16 07:10 parohy

Hi Tomas

thanks for reporting this issue! If you want a quick fix for your problem, use android:maxLines="4" in your layout file instead of using expandText.setMaxLines(4); in your Activity / Fragment.

I'll add support for also using the setMaxLines() method.

Good luck!

Cliffus avatar Oct 15 '16 15:10 Cliffus

how to use this textview in listview in listitem row with simpleAdapter?

Adnan-addi avatar Feb 01 '17 01:02 Adnan-addi

Setting MaxLines in code is crucial for XML-free Kotlin's anko layouts...

pasniak avatar Jul 29 '18 13:07 pasniak

I've made a forked version of this library that allows setting the max lines in code: https://github.com/zacharee/Android-ExpandableTextView.

Here's the relevant commit: https://github.com/zacharee/Android-ExpandableTextView/commit/5fc91d32002d328b354cad6036da7ffc41f828d8

I just changed any calls to setMaxLines() inside the ExpandableTextView class to call the super method, and then overrode both setMaxLines() and getMaxLines() to properly set and report ExpandableTextView's maxLines field.

zacharee avatar Jun 25 '20 19:06 zacharee