Android textView点击滚动(跑马灯)效果

Android textView点击滚动(跑马灯)效果

布局文件:

 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     <TextView

13         android:layout_width="wrap_content"

14         android:layout_height="wrap_content"

15         android:layout_marginLeft="200dp"

16         android:text="数值" />

17 

18     <TextView

19         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     <TextView

31         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     @Override

14     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             @Override

26             public void onClick(View v) {

27                 // TODO Auto-generated method stub

28                 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             @Override

40             public void onClick(View v) {

41                 // TODO Auto-generated method stub

42                 tv1.setEllipsize(TextUtils.TruncateAt.MARQUEE);

43                 tv1.setFocusable(true);

44                 tv1.setFocusableInTouchMode(true);

45                 tv1.requestFocus();

46 

47             }

48         });

49 

50     }

51 }

 

你可能感兴趣的:(textview)