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" >
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.
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.
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.
Related
I am using a Vaadin 10 (Flow) Grid to stream data to new rows, and I am trying to add a custom image icon to my TemplateRenderer.
I have a TemplateRenderer setup like this:
TemplateRenderer<TradeUni> sizee = TemplateRenderer.<TradeUni>
of("<div class$=\"[[item.class]]\">[[item.size]]</div>")
.withProperty("class", cssClassProvider)
.withProperty("size", TradeUni::getSize);
Which displays my numbers correctly in the grid cell like this:
I would like to have my image rendered inside the same cell, to the left of the numbers.
This was my (very crude) attempt to import it using html:
TemplateRenderer<TradeUni> sizee = TemplateRenderer.<TradeUni>
of("<div class$=\"[[item.class]]\"><img src=\"i.imgur.com/3LQBglR.png\">[[item.size]]</div>")
.withProperty("class", cssClassProvider)
.withProperty("size", TradeUni::getSize);
Which give's me this:
I think that I might have to wrap the image and numbers into a HorizontalLayout with the image being a separate component - I think I could handle that, but I am unsure of how to do the actual rendering of the image. I can probably accomplish it simply with the internal Vaadin Icons set, but I need to use my own little images.. all icons that I am going to use will be at or less than 25 x 25px.
Thank you so much in advance!
I think you're on the right track, but there's one small detail that causes you trouble. The URL i.imgur.com/3LQBglR.png doesn't define a protocol, which means that the entire string will be treated as a path relative to the location of the hosting page. It will thus try to find a file in a directory named i.imgur.com on your own server.
To fix this, you need to also include the protocol in the image URL, i.e. https://i.imgur.com/3LQBglR.png.
I can also offer a small suggestion for how to make the code easier to read. HTML also supports using ' for enclosing attribute values. This is more convenient to use from Java string since you don't need to use \ to escape ' characters. Your template string could thus be "<div class$='[[item.class]]'><img src='https://i.imgur.com/3LQBglR.png'>[[item.size]]</div>".
I would like to see visually how much space each box takes with as little effort/changes to the code as possible.
I would like to know if it's possible to just put a line around the outer margins of the View or ViewGroup object.
Since it's just for debugging and styling I would like to also quickly turn it off, so I do rather make the changes to my code in one place so it's easy and quick to undo. Is this a default option I am missing? Somehow I expect this feature to exist already.
Here someone asks a different but slightly related question with not a nice answer for my case.
Here someone gives an answer on how to outline one View.
Border for an Image view in Android?
Code-wise you could follow the answer to the first link you posted and create a drawable with the name "developer_borders" or something similar and apply it to every view you wish to have its borders visible.
To easily remove it afterwards, you can right-click the directory of your project and click Replace in Path.... For Text to find you want to search for android:background="#drawable/developer_borders and for Replace with don't use anything. This will find every occurrence of what you are searching and replace it with an empty string.
There might be an easier option. Some devices have quite powerful Developer Options. "Show layout bounds" is what you want but take a look at the rest while you are at it, some are pretty awesome.
I have a strange effect with a4j:repeat when using rich:toolbar in RichFaces. In my little example I just place a couple of icons on the toolbar. If I do it manually, they are all separately placed into <td>...</td>. But if let them generate by a list using a4j:repeat, they will all be placed together within one <td>...</td>.
The result of this is that those placed manually are more far from each other in the view. Those who were generated, stick together.
I believe the difference is, that the rich:toolbarGroup thinks of the a4j:repeat as one object, and of the manually placed ones as serveral objects.
I tried out with c:forEach as well, but I get exactly the same effect.
Does anyone know how to define the a4j:repeat objects as separate? Or if it is another problem, how to solve it?
If you're only worried about the spacing you can increase it by CSS.
<a4j:repeat> is not a good thing to use with the toolbar. If the icons you put in are supposed to have some sort of functionality attached to them you'd have a problem assigning it dynamically.
Need to add it to textview, for example, standard java-code.
What do you exactly mean? You may want to change Typeface of TextView to monospace, this will make your TextView look similar to code block here at stackoverflow.
This font is monospace
Code to make it look like this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:typeface="monospace"
android:text="This font is monospace" />
or in Java:
yourTextview.setTypeface(Typeface.MONOSPACE, Typeface.NORMAL);
Edit:
So, you need some Java code formatting library, the best would be if it returned result in HTML code, so it could be easily put into TextView.
I don't know if there is something like this for free, but here are few resources you may be interested in:
How to pretty print XML from Java?
Stand-alone Java code formatter/beautifier/pretty printer?
Edit2:
You may also use one of these JavaScript libraries:
http://alexgorbatchev.com/SyntaxHighlighter/
http://code.google.com/p/google-code-prettify/
along with custom WebView to show pretty formatted code.
I am going through the android hello world tutorial, and have been stuck when trying to create an XML UI. For some reason, even on a new program, in which I have made no changes to the default build, it gives the error java.lang.NullPointerException after every character I type. I can't figure out why it is doing this, as I am just trying to edit the text between the Text I want to set it to say something other than what is set by default. However, even with a fresh build, no changes, and I just try to change the text within the xml tags, it still gives the error. What do I need to do to allow it to let me type? I am using the eclips IDE and the android sdk. I was able to do the first part of the tutorial that doesn't involve XML.
Just guessing, but I suspect you are doing something like the following:
<TextView android:text="#string/hello" />
and you are editing it to
<TextView android:text="#string/helloWorld" />
without creating a reference in res/values/strings.xml .
If this is the case, go to strings.xml and edit the proper string there, for example
<string name="hello">Hello World!</string>
becomes
<string name="hello">Hello everybody!</string>
Ok, I finally found the answer somewhere else, it was something wrong with how the file was created by default. I have to add the element xmlns:android as follows <resources xmlns:android="http://schemas.android.com/apk/res/android" />
Interestingly enough, the file will work if I type it one character at a time, dismissing the pop up with each keystroke. However the new element eliminates the pop ups. I am not sure why the error would pop up, yet the program still compile and run correctly on my avd. Oh well, if you have this error add the element and it goes away
I think in your typing contain UTF-8 not pure ASCII. You can change in eclipse by
in Ecipse IDE Window> preference> Under General tab, select workspace.
In text file encoding choose other, in these choose UTF-8 . It will be ok