android 之textview滚动,,跑马灯

一定很羡慕app中广告的动态效果,小白这里自学了这种效果。
很简单 只需要简单的设置几个属性就ok了。

上代码,求建议。请看代码

1、这里是布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >

 

    <TextView

        android:id="@+id/textview"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

         android:background="#00ffff"

        android:textColor="#ff00ff"

        android:singleLine="true"

        android:ellipsize="marquee"

        android:marqueeRepeatLimit="marquee_forever"

        android:focusable="true"

        android:focusableInTouchMode="true"

       />

 

</RelativeLayout>

2、这里是activity源码

package com.example.gundongtextview;

 

import android.os.Bundle;

import android.app.Activity;

import android.text.Html;

import android.text.method.LinkMovementMethod;

import android.view.Menu;

import android.widget.TextView;

 

public class MainActivity extends Activity {

private TextView tv;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

tv=(TextView) findViewById(R.id.textview);

String str="16日到24日进行的国考报名已进入“下半场”,截至昨天17:00,已经有将近39万名考生通过审核,仍有703个职位无人报考。";

tv.setText(str);

//当然可以用html来设置textview内容,,添加超链接等,此处不赘述tv.setMovementMethod(LinkMovementMethod.getInstance());//可以不写这句。最好加上。

}

}

 

3、个人感受。属性很重要,然后就是可以在文本中做其他操作,比如弄个超链接--个性嘛。随便啦。

  第一点,首先确保单行文本,即singleLine

第二点,设置markquee  并且设置重复模式

第三点,能够获得焦点

第四点:

android:focusableInTouchMode="true"

这个属性很重要,不能少。

 

 

 

欢迎技术交流。QQ964079433

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章