1. 程式人生 > >TextView文字橫向自己主動滾動

TextView文字橫向自己主動滾動

int mod -- ont -c xtend img 自己 chmod

??????????效果截圖:

?

?????????????????????????? 技術分享圖片技術分享圖片

布局文件:

<?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:background="#ffffff"
????????????? android:gravity="center"
??????? >

??? <TextView android:id="@+id/text1"
????????????? android:layout_width="80dp"

????????????? android:layout_height="40dp"
????????????? android:ellipsize="marquee"
????????????? android:marqueeRepeatLimit="marquee_forever"
????????????? android:focusable="true"
????????????? android:scrollHorizontally="true"
????????????? android:focusableInTouchMode="true"
????????????? android:layout_centerInParent="true"
????????????? android:textColor="#0551A5"
????????????? android:layout_marginLeft="20dp"
????????????? android:layout_marginRight="20dp"
????????????? android:singleLine="true"/>
??? <!--android:focusable="true"是否獲取焦點-->
??? <!--focusableInTouchMode:通過觸摸獲取焦點-->
??? <!--android:ellipsize="marquee"設置為跑馬燈-->
??? <!--android:marqueeRepeatLimit="marquee_forever"滾動次數裏面能夠直接寫數字-->
??? <!--marquee_forever表示永遠滾動-->
??? <!--android:scrollHorizontally="true"水平滾動-->
??? <!--android:singleLine="true"單行輸入-->
</LinearLayout>

Java代碼:

package com.example.MargueeTextView;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MyActivity extends Activity {
??? private TextView text1;
??? /**
???? * Called when the activity is first created.
???? */
??? @Override
??? public void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.main);
??????? text1=(TextView)findViewById(R.id.text1);
??????? text1.setText("春光無限好,僅僅是近黃昏………………");
??? }
}

?源代碼下載地址

?

TextView文字橫向自己主動滾動