grantland / android-autofittextview

A TextView that automatically resizes text to fit perfectly within its bounds.
Apache License 2.0
4.27k stars 688 forks source link

Issue with using inside listview #40

Open jagatappv opened 9 years ago

jagatappv commented 9 years ago

Hey,

I have used this library.

Its working fine if i am using in any view.

But when i integrate this library with list view. It changing text size randomly.

Let me add my code here, I have added this code inside my list item.

                         <me.grantland.widget.AutofitTextView
                        android:id="@+id/tvAudience"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:layout_gravity="center_vertical"
                        android:text="Publifhbgdfgdfgfggfgc"
                        android:maxWidth="@dimen/max_width_targetaudience"
                        android:singleLine="true"
                        android:textColor="@color/blue_text" />

Can anyone help me to resolve this issue?

Thanks

grantland commented 9 years ago

This is could possible be due to view recycling. Could you post some ListView + Adapter code that repros this issue?

noder123 commented 9 years ago

Bump. Anybody can reproduce it with a simple ListView/RecyclerView and an Adapter.

cranberyxl commented 9 years ago

This happens when you're layout_width is wrap_content. Changing it to match_parent fixed it for me. It has to know how big to be able to draw it. And for some reason after it's recycled, it keeps the old width.

gang018 commented 9 years ago

@cranberyxl, thanks a lot! Your solution also helped me :)