TextView實現跑馬燈效果
使用TextView簡單實現燈箱跑馬燈效果:
直接上代碼:activity_main.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"
tools:context="com.example.t.MainActivity" ><TextView android:id="@+id/notice" android:layout_width="fill_parent" android:layout_height="fill_parent" android:ellipsize="marquee"//以橫向滾動方式顯示(需獲得當前焦點時) android:focusable="true"//允許獲取焦點 android:focusableInTouchMode="true"//設置是否觸摸模式。 android:gravity="center" android:marqueeRepeatLimit="marquee_forever"//一直滾動 android:scrollHorizontally="true"//設置文本超出TextView長度的情況下,是否出現橫拉條 android:singleLine="true"//單行顯示 android:textSize="20sp" android:textColor="#FF0000" android:text="回收二手航母、導彈、潛艇、坦克、翻新原子彈啦!!!!..." android:textStyle="bold" /> </RelativeLayout> </pre>
JAVA代碼:MainActivity.javapackage com.example.t;import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.Window; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE);//無標題 setContentView(R.layout.activity_main); } @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; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } </pre>
本文由用戶 pxdb 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!