布局文件:

 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 }

更多相关文章

  1. Android(安卓)Studio实现代码混淆
  2. Android常用功能代码总结一
  3. android TextView的跑马灯效果的实现
  4. android在java代码中绘制矩形框
  5. 用ant实现自动打包android(二) -- android代码混淆
  6. Android安装卸载程序解析
  7. Android(安卓)framework完整源码下载
  8. Android通过WebView调用 JS 代码
  9. android 常用intent

随机推荐

  1. 基于SARIMA-LSTM的门诊量预测研究
  2. 人在回路的数据准备技术研究进展
  3. W EB:一种基于网络嵌入的互联网借贷欺诈预
  4. 农业大数据建设的需求、模式与单品种全产
  5. Hadoop下水环境模拟集群运算模式
  6. 《大数据》编辑部恭贺新春!!!
  7. 基于APMSSGA-LSTM的容器云资源预测
  8. 基于数据空间的电子病历数据融合与应用平
  9. 处理类似Globeimposter-Alpha865qqz勒索
  10. 数据管护技术及应用