Reputation: 864
Is it possible to have a textview which contains some text at the leftmost side and some text at the rightmost side of the textview.
For Example: I want to have a textview which should appear like this
/////////////////
text a
////////////////
Upvotes: 2
Views: 2003
Reputation: 14472
textView.setText("text" + spaces(10) + "a");
String spaces(int numberOfSpaces){
if (numberOfSpaces < 1){return "";}
StringBuilder sb = new StringBuilder(" ");
for (int i=1;i<numberOfSpaces;i++){
sb.append(" ");
}
return sb.toString();
}
Upvotes: 0
Reputation: 15414
It is possible using a single TextView. Just put the text in HTML format like
<string name="my_string">
<![CDATA[
<!DOCTYPE html>
<html>
<body>
<h1><span>Sunil bn</span><span style="float:right">Your Text</span></h1>
</body>
</html>
]]>
</string>
in the strings file. Suppose the name of the string is "my_string". Then in your code set the text on the TextView using
myTextView.setText(Html.fromHtml(getResources()
.getString(R.string.my_string)));
Upvotes: 2
Reputation: 15847
No its not possible with single TextView.
You can try textview.setText("test _____ "+"a");
but it will not work perfectly.
But you can take two TextView
then you can achieve this.
Upvotes: 1