<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- android:singleLine="true"表示只能单行显示 --> <!-- android:ellipsize="marquee"表示字幕效果 --> <!-- android:marqueeRepeatLimit="marquee_forever"表示一直重复 --> <TextView android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:background="#FFFFFF" android:textColor="#000" android:textSize="20dp" android:focusableInTouchMode="true" android:layout_margin="10dp" android:padding="10dp"></TextView> </LinearLayout>
1 public class Main extends Activity { 2 /** Called when the activity is first created. */ 3 private TextView textView1; 4 5 @Override 6 public void onCreate(Bundle savedInstanceState) { 7 super.onCreate(savedInstanceState); 8 setContentView(R.layout.main); 9 textView1 = (TextView) this.findViewById(R.id.textview); 10 11 String html = "中新网10月10日电 据外电报道,美国科学家罗伯特J。<a href='http://www.baidu.com'>勒夫科维兹</a>(Robert J. Lefkowitz)与布莱恩·K·卡比尔卡(Brian K. Kobilka)因在G蛋白偶联受体方面的研究获得2012年诺贝尔化学奖。"; 12 CharSequence charSequence = Html.fromHtml(html); 13 textView1.setText(charSequence); 14 textView1.setMovementMethod(LinkMovementMethod.getInstance()); 15 16 } 17 }