Android textView點擊滾動(跑馬燈)效果

來源:互聯網
上載者:User

標籤:

布局檔案:

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="vertical" 6     android:paddingBottom="@dimen/activity_vertical_margin" 7     android:paddingLeft="@dimen/activity_horizontal_margin" 8     android:paddingRight="@dimen/activity_horizontal_margin" 9     android:paddingTop="@dimen/activity_vertical_margin"10     tools:context="com.example.textview.MainActivity" >11 12     <TextView13         android:layout_width="wrap_content"14         android:layout_height="wrap_content"15         android:layout_marginLeft="200dp"16         android:text="數值" />17 18     <TextView19         android:id="@+id/tv"20         android:layout_width="match_parent"21         android:layout_height="wrap_content"22         android:layout_marginLeft="200dp"23         android:ellipsize="end"24         android:marqueeRepeatLimit="marquee_forever"25         android:scrollHorizontally="true"26         android:singleLine="true"27         android:text="莫聽穿林打葉聲,何妨吟嘯且徐行,竹杖芒鞋輕勝馬,誰怕?一蓑煙雨任平生."28         android:textSize="18sp" />29 30     <TextView31         android:id="@+id/tv1"32         android:layout_width="match_parent"33         android:layout_height="wrap_content"34         android:layout_marginLeft="200dp"35         android:ellipsize="end"36         android:marqueeRepeatLimit="marquee_forever"37         android:scrollHorizontally="true"38         android:singleLine="true"39         android:text="莫聽穿林打葉聲,何妨吟嘯且徐行,竹杖芒鞋輕勝馬,誰怕?一蓑煙雨任平生."40         android:textSize="18sp" />41 42 </LinearLayout>

代碼:

 1 package com.example.textview; 2  3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.text.TextUtils; 6 import android.view.View; 7 import android.view.View.OnClickListener; 8 import android.widget.TextView; 9 10 public class MainActivity extends Activity {11     private TextView tv, tv1;12 13     @Override14     protected void onCreate(Bundle savedInstanceState) {15         super.onCreate(savedInstanceState);16         setContentView(R.layout.activity_main);17 18         initView();19     }20 21     private void initView() {22         tv = (TextView) findViewById(R.id.tv);23         tv.setOnClickListener(new OnClickListener() {24 25             @Override26             public void onClick(View v) {27                 // TODO Auto-generated method stub28                 tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);29                 tv.setFocusable(true);30                 tv.setFocusableInTouchMode(true);31                 tv.requestFocus();32 33             }34         });35 36         tv1 = (TextView) findViewById(R.id.tv1);37         tv1.setOnClickListener(new OnClickListener() {38 39             @Override40             public void onClick(View v) {41                 // TODO Auto-generated method stub42                 tv1.setEllipsize(TextUtils.TruncateAt.MARQUEE);43                 tv1.setFocusable(true);44                 tv1.setFocusableInTouchMode(true);45                 tv1.requestFocus();46 47             }48         });49 50     }51 }

 

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.