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

为了达到这样的效果,我尝试使用2 TextView秒.
<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>
Run Code Online (Sandbox Code Playgroud)
我得到以下结果.
相当接近.但不是我想要的.这是因为第2行和第3行没有对齐到最左边.第二行和第三行的最左侧空间由TextView大字体占用.

有没有更好的技术我可以使用,比如Flipboard中的那个?
通过使用一个单一的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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1684 次 |
| 最近记录: |