Manabu-GT / ExpandableTextView

Android's TextView that can expand/collapse like the Google Play's app description
Apache License 2.0
4.08k stars 791 forks source link

It have a bug, I don't know why #2

Closed com314159 closed 9 years ago

com314159 commented 9 years ago

You can try add a button a your demo project, and on the onClickListener you set the dummy_text2 again. like

    expTv2.setText(getString(R.string.dummy_text2));

    Button bt = (Button) findViewById(R.id.test);

    bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            expTv2.setText(getString(R.string.dummy_text2));
        }
    });

after the button clicked, (that is the same text is set again after view created and when textview is collapsed), the textview can't expand fully. I found the mMeasuredTextHeight is a wrong value.

may be I can solve this problem.

thank you for your code.

com314159 commented 9 years ago

set different text will also cause the same problem

com314159 commented 9 years ago

solved by

add method: private int getTextViewRealHeight(TextView pTextView) { Layout layout = pTextView.getLayout(); int desired = layout.getLineTop(pTextView.getLineCount()); int padding = pTextView.getCompoundPaddingTop() + pTextView.getCompoundPaddingBottom(); return desired + padding; }

then in onMeasure change mMeasuredTextHeight = mTv.getMeasuredHeight() to mMeasuredTextHeight = getTextViewRealHeight(mTv);

Manabu-GT commented 9 years ago

Thanks, I will also look into this and get back to you.

Manabu-GT commented 9 years ago

Textview's getMeasuredHeight() was being affected by parent's heightMeasureSpec and not equal to the text's height. The fix will be merged in to the master branch soon and will be released as version 0.1.1 in the maven central.

Manabu-GT commented 9 years ago

The fix is in v0.1.1 and now published to the maven central. It should go live within a day.

Thank you for your help, "com314159 ".

Manabu