跑马灯效果

activity类:

public class MainActivity extends Activity {

TextView text;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

text = (TextView)findViewById(R.id.textView1);
text.setText("用户名");
text.setTextColor(Color.RED);
text.setText(Html.fromHtml("Hellodfrasdfsdfdsa<font color = red>Worfasdfsadfasdfasdld</font>"));

/*SpannableString ss = new SpannableString("Hello World");
ss.setSpan(new BackgroundColorSpan(Color.BLUE),0, 5, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
text.setText(ss);*/
}

@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;
}

}

XML文件:

<LinearLayout 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:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:textSize="50dp"
/>


</LinearLayout>

奋斗和第三方
原文地址:https://www.cnblogs.com/Smart-Du/p/4301967.html