TextView 滚动

来源:互联网 发布:个人备忘录软件 编辑:程序博客网 时间:2024/04/28 11:04

1TextViewMarquee.java文件:

public class TextViewMarquee extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.textview); 
        findViewById(R.id.widget28).setSelected(true); 
    } 

2textview.xml文件:

<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"> 
<TextView
   android:id="@+id/widget28"
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content"
   android:layout_alignParentRight="true"

   android:singleLine="true"
   android:ellipsize="marquee"
   android:fadingEdge="horizontal"
   android:marqueeRepeatLimit="marquee_forever"
   android:scrollHorizontally="true"

   android:textColor="#ff4500"
   android:text="Simple application that shows "
 />  
</RelativeLayout>

 

文字左右滚动三个属性: 
         android:singleLine="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 

大量文本内容滚动: 
TextView自己也可以实现多行滚动的,毕竟 ScrollView必须只能有一个直接的子类布局。只要在layout中简单设置几个属性就可以轻松实现。 
  <TextView 
    android:id="@+id/tvCWJ" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical"  <!--垂直滚动条 --> 
    android:singleLine="false"      <!--实现多行 --> 
    android:maxLines="15"            <!--最多不超过15行 --> 
    android:textColor="#FF0000" 
    /> 

为了让TextView动起来,还需要用到TextViewsetMovementMethod方法设置一个滚动实例,代码如下 
TextView tv  = (TextView)findViewById(R.id.tvCWJ);  
tv.setMovementMethod(ScrollingMovementMethod.getInstance()); 

0 0
原创粉丝点击