(1)Mainactivity.java
package com.example.android_textview_rollingsubtitles; import java.sql.Wrapper; import android.os.Bundle; import android.app.Activity; import android.text.Html; import android.text.TextUtils; import android.text.TextUtils.TruncateAt; import android.text.method.LinkMovementMethod; import android.view.Menu; import android.widget.TextView; public class MainActivity extends Activity { private TextView textview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textview =(TextView) this.findViewById(R.id.textveiw); String html = "Android <font color=‘blue‘><a href=‘http://test.com‘>Linux</a></font> 系统.太平洋电脑网提供Android手机大全全面服务信息,包含Android手机报价、参数、评测、比较"; CharSequence charsequence = Html.fromHtml(html); textview.setText(charsequence); //设置***灯效果 textview.setSingleLine(true); textview.setEllipsize(TextUtils.TruncateAt.MARQUEE); textview.setMarqueeRepeatLimit(-1); //设置内填充 textview.setPadding(5, 5, 5, 5); //设置宽度 textview.setFocusableInTouchMode(true); textview.setFocusable(true); //设置可以点击属性 textview.setMovementMethod(LinkMovementMethod.getInstance()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
(2)activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textveiw" android:focusableInTouchMode="true" android:padding="10dp" > </TextView> </RelativeLayout>
android_常用UI控件_01_TextView4_rollingsubtitles效果加链接文字,布布扣,bubuko.com
时间: 2024-10-18 09:31:52