In my application I have a quiz page..
It have questions and answer.. Each question have question number..
Sample question:
Which one of the following would make a suitable inert electrode in
the electrolysis of sodium sulfate solution?
But I want to give some space for next line to align properly..
Which one of the following would make a suitable inert electrode in
the electrolysis of sodium sulfate solution?
Currently I acheive with two textviews (one for number another for question) within linearlayout.
My question:
This alignment possible with same textview?
You can try the android:gravity="center". This might look better.
On applying it, the text would be looking like
Q1: This will be the line of your question and
this will be the second line.
you can use two textviews one for the number of the question and the other for the question and answer just seperate them with a "\n"
or add tab space with "\t" before the answer , both should work ,
much luck.
You can try '\t' it make space but in android text align based on device width.
For example:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1.Which one of the following would make a
suitable inert electrode in \t \t \t the electrolysis of sodium sulfate solution?"/>
Related
I have a long text which is required to float over edit text as the requirement says. I went through many such question here, but couldn't find the proper answer. How can we make that possible? I have tried using a '\n' with the hint string but it didn't work.
you can add \n without giving any space. example shown below
<string name="hint_manish">Hint first line\nHint second line\nHint third line</string>
The hint takes on the behavior of the Edittext it's related to.
Adding
android:inputType="text|textMultiLine"
will give you multiple line hint.
What I would like to achieve is an effect that looks like this with a TextView:
Basically having a background, but keeping the space between the lines. The only solution I came up with was using one TextView for each line of text, but I would prefer a cleaner one using only one multiline TextView.
Any ideas?
Use spanned text for each line. Read the Spannable API.
please refer to this answer here as it describes how to implement spacing between multiple lines in a TextView , using the following properties :
android:lineSpacingMultiplier
android:lineSpacingExtra
Hope that Helps .
Regards
What you can do is use mark tag in html to textview.
myTextView.setText(Html.fromHtml("<mark>heading highlighted</mark>"));
I need to set a button's text to just ?.
I'm happy to do it via Java, but would rather do it via the XML.
Is it possible?
I've tried android:text="?" and android:text="?" but it did not work.
Then I set one of the string resources to ?, and when that did not work I set it to ?referenced that but it doesn't work!
How do I set the button caption to ? using XML?
You need to escape the question mark...
android:text="\?"
Write "\?" Intead normal or ASCII form.
You try this way.. just give space before or after ? this will work i think..
android:text=" ?" or android:text="? "
give the space before writing the ?(android:text=" ?")...it's working fine.other wise. you have to add image to button(android:background="#drawable/image"). or u need to take imagebutton add question mark image to it.
Part of your problem is that in some versions of the Eclipse Android Layout Editor, it will freak out with a question mark as its text on a button. I submitted a bug report, and after a year I received a note saying that the bug is fixed.
So make sure you have version 21.1 or greater of the API to get the bug fix.
See my question about this: Android Layout Editor Freaks Out on Question Mark
Hope this helps.
Try using a \ before the question mark like this "\?".
I have a TextView with about 10 rows. I want to have the lines more separated from each other. I can't seem to find an attribute for doing that. I tried with: android:includeFontPadding="true" but the text got all weird like stretched or something. Is there any attribute that I don't know about to do that?
Thanks in advance.
Use android:lineSpacingMultiplier="1.2" or some number greater than 1
You can use android:lineSpacingExtra="xxdp"
This property makes
"short and very-long-word"
to
"short and"
. But I want to have smth. like
"short and very-lon..."
Right now I truncate the String in Java code. However, thats based on the number of characters and not the actual length of the link. So, the result isn't very nice.
String title;
if(model.getOrganization().length() > 19) {
title = model.getText().substring(0, 15).trim() + "…";
} else {
title = model.getText();
}
((TextView) findViewById(R.id.TextViewTitle)).setText(title);
Update
Just noticed, this property actually adds "..." in a few cases. But not in all of them:
12345678901234567890 becomes
"12345678901234..."
However,
"1234567890 1234567890"
becomes "1234567890" and not
"1234567890 123..."
Update 2
Now it really gets funky! I just set singleLine=true and removed maxLine (The bug appears with and without setting ellipsize attribute)...
This is a screenshot take from Motorola Milestone with android 2.1 update 1. Same happens on HTC Desire with the same android version
Update 3
Now I use android:ellipsize="marquee". That seems to be the only properly working setting. It's also only moving, when focused. I see it in many other apps also. I guess its common practise.
If it's for a single line try this:
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
It worked for me.
I had a similar problem and setting this property to the TextView helped:
android:singleLine="true"
Also, I was using a RelativeLayout so I limited the space the TextView could take by setting a left margin to a button to the right of the TextView, so that the text cannot expand further and is forced to truncate its content.
Maybe it's not the solution to your problem, but it helped me in a similar situation.
See my update 3. The workaround was using " marquee". I have seen many apps doing that at this time.
Now, with new versions of Android this feature is most likely fixed and will work as expected. (my guess)
Maybe you could take a look at how the private Ellipsizer class used by the OS works and modify it for your app?
Edit: Here's a working link - http://androidxref.com/5.1.0_r1/xref/frameworks/base/core/java/android/text/Layout.java#1830