JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 529 forks source link

Gravity is not working correct #149

Open andreasschiestl opened 8 years ago

andreasschiestl commented 8 years ago

Hi! I think there is a problem with centering the content of the IconTextView when the text is set after the first layout.

In my app i have a dashboard with tiles. some of them are static and some of them loaded via network from a webservice. The loading is done with a AsyncThread. When i try so set the icon in onPostExecute the icon is not centered correct.

Here is a Example: The tile with the label "Baupläne (2)" is static and the icon is set during the view creation. The other one with the label "Baupläne (1)" is dynamic, the icon leaved empty and creation and is set after the content is loaded from the server. screenshot_20151227-124036 screenshot_20151227-124051

This is the layout ressource i used:

<com.joanzapata.iconify.widget.IconTextView
            android:id="@+id/dashboardTile_icon"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dashboardTiles_iconSize"
            android:layout_gravity="top"
            android:layout_marginTop="@dimen/dashboardTiles_iconMarginTop"
            android:gravity="center"
            android:textSize="@dimen/dashboardTiles_iconSize"
            android:textColor="#FFFFFF" />

nothing of the view is changed by code except the text and textColor.

Any Ideas for a workaround or a fix?

andreasschiestl commented 8 years ago

adding android:bufferType="spannable" seems to fix the problem, but i don't know exactly why. Maybe someone coudl explain the issue.

JoanZapata commented 8 years ago

Interesting. I don't where the problem comes from, I've had use cases like yours but all went fine. I'll try to reproduce and fix it, thanks for sharing a workaround!

solominh commented 8 years ago

I have the same problem with TextView gravity too. When i change TextView width in method onMeasure, the icon doesn't adjust itself to the new width.