Unable to Set Text Size Using FlowTextView

做~自己de王妃 提交于 2020-01-05 05:44:08

问题


I found a library which allows an app to wrap text around an image - however once implemented it changed the size of my text - how can the text size be increase when using this library?

android:textSize= has no impact on the text size.

Neither does:

FlowTextView titleTv = (FlowTextView) findViewById(R.id.titleTv);
((FlowTextView) findViewById(R.id.titleTv)).setTextSize(20);

https://code.google.com/p/android-flowtextview/

Example:

<com.pagesuite.flowtext.FlowTextView
    android:id="@+id/titleTv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"
    android:text=""
    android:textSize="20sp" >

回答1:


In the short term a call to invalidate will probably get it working:

FlowTextView titleTv = (FlowTextView) findViewById(R.id.titleTv);
titleTv.setTextSize(20);
titleTv.invalidate();

However, I suspect you are using the JAR file right? It is quite out of date so I would recommend checking the source code out and using it as an android library project - setTextSize() should work properly then without needing a call to invalidate() (plus various other bug fixes etc).

Also - I never added the ability to set the text size via XML - wouldn't be too hard to add this though.




回答2:


I checked the code of android-flowtextview and they have the text size hardcoded (check line 131 here). You have to change their source code or use the public method setTextSize(int).

Also, this link might help you, as seems that someone already did something as you are trying to do.




回答3:


https://code.google.com/p/android-flowtextview/source/browse/trunk/src/com/pagesuite/flowtext/FlowTextView.java

There's a 'setTextSize(int)' method that should do exactly what you're looking for.

If you want to set it from XML, it's a little more involved. Since FlowTextView's constructors ignore the AttributeSet that gets passed in, you'll have to code this yourself. Follow guides like this: http://kotikan.com/blog/posts/2012/09/android-attributes to figure out how to add custom attributes to your views.



来源:https://stackoverflow.com/questions/20706534/unable-to-set-text-size-using-flowtextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!