[androidUI特效]android中TextView中如何設定水平滾動效果

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   color   ar   os   sp   

    如何讓文本實現走馬燈的效果,下面就一起實現下吧~~~~~~

package irdc.ScrollingText;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class ScrollingText extends Activity{  public TextView t1;  /** Called when the activity is first created. */  @Override  public void onCreate(Bundle savedInstanceState)  {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    t1= (TextView) findViewById(R.id.t1);    t1.setText("哈哈我的跑馬燈程式接下來是歌詞呵呵:沉魚落雁,閉月羞花,美的無處藏,人在身旁,如沐春光");    t1.setTextSize(30);    t1.setHorizontallyScrolling(true);    t1.setFocusable(true);  }}

   在這段程式中我設定了t1的焦點為真(意思為焦點在t1上),同事我設定了t1的文本顯示能超過其顯示地區(t1.setHorizontallyScrolling(true) 設定的這行的目的是為了不讓程式自動給文本折行,使之為單行),當然這些屬性你都可以在XML檔案中定義。接下來我們看看main.xml檔案。

<?xml version="1.0" encoding="utf-8"?><AbsoluteLayoutandroid:id="@+id/widget35"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/black"xmlns:android="http://schemas.android.com/apk/res/android"><TextViewandroid:id="@+id/t1"android:layout_width="100px"//此處為文本顯示地區的寬度此值必須比你的文本寬度要小否則是沒有效果的android:layout_height="wrap_content"android:text="@string/str_id"android:textColor="@drawable/green"android:layout_x="61px"android:layout_y="69px"android:scrollX="2px"android:singleLine="true"android:ellipsize="marquee"android:marqueeRepeatLimit="marquee_forever"></TextView><ViewStub android:layout_y="221dip" android:layout_;wrap_content" android:layout_x="103dip" android:id="@+id/ViewStub01" android:layout_height="wrap_content"></ViewStub></AbsoluteLayout>
大家注意到在TextView中我添加了三行藍色的欄位,其中singleLine表示TextView中文本為單行文本如果你在你的程式中設定了setHorizontallyScrolling(true)在這你可以不寫了,接下來就是我們的關鍵之處了ellipsize="marquee" 此語句表示我們將TextView設定為了一個走馬燈,marqueeRepeatLimit="marquee_forever"  表示走馬燈的滾動效果重複的次數,你可以填一個自然數。好了接下了編譯試試
轉載自:http://www.lupaworld.com/home/space-345712-do-blog-id-138560.html

[androidUI特效]android中TextView中如何設定水平滾動效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.