I would like to display a paragraph of long text as follow. Here is the snapshot from Flipboard.
In order to achieve such effect, I tried to use 2 TextView
s.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="T" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="76dp"
android:text="op British supermarket Tesco (LSE: TSCO) (NASDAQOTH: TSCDY.US) is due to announce its half year results on" />
</LinearLayout>
I get the following result.
Quite close. But not what I want. This is because the 2nd line and the 3rd line is not align to the left most. The left most space for 2nd line and 3rd line, is occupied by the TextView
with large font.
Is there any better technique I can use, such as the one in Flipboard's?
To set the maximum length for text in TextView widget, set the maxLength attribute with required number of length.
The on-screen keyboards of Android devices will capitalize the first letter of a sentence by default thanks to a built-in "Text correction" tool. Gboard, the default keyboard app for Android devices, allows you to change this feature through the gear icon located at the top of the keyboard.
By using a single TextView
with BufferType.SPANNABLE
will solve the problem.
final SpannableString spannableString = new SpannableString(title);
int position = 0;
for (int i = 0, ei = title.length(); i < ei; i++) {
char c = title.charAt(i);
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
position = i;
break;
}
}
spannableString.setSpan(new RelativeSizeSpan(2.0f), position, position + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//titleTextView.setText(spannableString.toString());
titleTextView.setText(spannableString, BufferType.SPANNABLE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With