Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for "Text is not completely shown in Expanded State (Height Calculation Issue)" #75

Open
harismuneer opened this issue Sep 10, 2020 · 2 comments

Comments

@harismuneer
Copy link

Incase of large text, the text isn't shown completely in expanded state. This is still a bug in the latest version of this repository as of today and needs to be fixed in the next release @Manabu-GT . For now, following is the solution explained clearly.

SOLUTION

In ExpandableTextView class, in the onMeasure method: Cut the line

       mTextHeightWithMaxLines = getRealTextViewHeight(mTv);

and paste it right below this line

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

Or for ease, you can directly replace your onMeasure method with the method below.

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // If no change, measure and return
        if (!mRelayout || getVisibility() == View.GONE) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            return;
        }
        mRelayout = false;

        // Setup with optimistic case
        // i.e. Everything fits. No button needed
        mToggleView.setVisibility(View.GONE);
        mTv.setMaxLines(Integer.MAX_VALUE);

        // Measure
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        //--- Previously the mTextHeightWithMaxLines was initialized here ---//       

        // If the text fits in collapsed mode, we are done.
        if (mTv.getLineCount() <= mMaxCollapsedLines) {
            return;
        }

        // Doesn't fit in collapsed mode. Collapse text view as needed. Show
        // button.
        if (mCollapsed) {
            mTv.setMaxLines(mMaxCollapsedLines);
        }
        mToggleView.setVisibility(View.VISIBLE);

        // Re-measure with new setup
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

       mTextHeightWithMaxLines = getRealTextViewHeight(mTv);

        if (mCollapsed) {
            // Gets the margin between the TextView's bottom and the ViewGroup's bottom
            mTv.post(new Runnable() {
                @Override
                public void run() {
                    mMarginBetweenTxtAndBottom = getHeight() - mTv.getHeight();
                }
            });
            // Saves the collapsed height of this ViewGroup
            mCollapsedHeight = getMeasuredHeight();
        }
    } 

This was also discussed in this issue here #5 but the solution wasn't explained clearly.

@ghost
Copy link

ghost commented Sep 10, 2020

Is it AndroidX compatible now?

@harismuneer
Copy link
Author

Is it AndroidX compatible now?

Some of the library versions used in the original repository are outdated now. I had to clone this repository and update the versions especially the annotation libraries like

import android.support.annotation.DrawableRes;

with the AndroidX ones:

import androidx.annotation.DrawableRes;

Some libraries used in the build.gradle file were also updated. Therefore, after these modifications, I had to include this as a new module in the project since its now a customized library.

If I get some time then I will try to fork this project, update the libraries and generate the PR but I am quite occupied by work these days. It would be great if you or someone else could do the needful.

dimskiy added a commit to dimskiy/ExpandableTextView_fork that referenced this issue Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant