Android 如何使文本视图中的第一个字符比其他字符大得多

Android 如何使文本视图中的第一个字符比其他字符大得多,android,Android,我想显示一段长文本,如下所示。这是Flipboard的快照 为了达到这样的效果,我尝试使用2TextViews <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView3"

我想显示一段长文本,如下所示。这是Flipboard的快照

为了达到这样的效果,我尝试使用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>

我得到以下结果

非常接近。但不是我想要的。这是因为第2行和第3行未与最左侧对齐。第二行和第三行最左边的空间被大字体的
TextView
占据


有没有更好的技术可以使用,比如Flipboard中的技术?

对我来说,您可能使用了3种文本视图: 1段信 2-第一和第二行 3-文本的其余部分。

试试这个

布局XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal" >

<TextView
    android:id="@+id/bigChar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:gravity="center_vertical"
    android:text="T"
    android:textSize="40sp" />

<TextView
    android:id="@+id/sideText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_toRightOf="@id/bigChar"
    android:gravity="center_vertical"
    android:maxLines="2" />


<TextView
    android:id="@+id/spillText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/bigChar"
    android:layout_alignParentLeft="false"
    android:layout_below="@id/bigChar"
    android:layout_marginLeft="5dp"
    android:layout_marginTop="-5dp"
    android:gravity="center_vertical" />
</RelativeLayout>

通过将单个
TextView
BufferType.SPANNABLE
一起使用,可以解决此问题

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);
final SpannableString SpannableString=新SpannableString(标题);
int位置=0;
for(int i=0,ei=title.length();i如果((c>='a'&&c='a'&&c='0'&&c)只需使用
HTML
标记并使用
HTML.fromHtml()加载数据
TextView
WebView
@Andrew Spannable text是个好主意。谢谢。我添加了这一点作为答案。但是在Java代码中,如何确定要在哪些文本视图中放置哪些内容呢?在其中使用WebView很好,但我可能不会这样做。你需要知道有多少文本会填充first 2文本视图,然后减去字符串。检查此项:和。
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);