关于跑马灯的体会

1、 android:singleLine="true"虽然被不建议使用,但是跑马灯必须是它。如果改为android:maxLines="1",不能实现跑马灯效果。

2、 android:marqueeRepeatLimit="marquee_forever" 是否使用,没关系。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:text="跑马灯效果,点击暂停,再点击恢复" />

    <TextView
        android:id="@+id/tv_marquee"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:textColor="#000000"
        android:textSize="17sp"
        android:marqueeRepeatLimit="marquee_forever"
        android:text="快讯:红色预警,超强台风“莫兰蒂”即将登陆,请居民关紧门窗、备足粮草,做好防汛救灾准备!" />
</LinearLayout>
package com.example.administrator.myapplication50;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity  implements View.OnClickListener {

    private TextView tv_marquee;
    private boolean bPause = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout3);

        tv_marquee = (TextView) findViewById(R.id.tv_marquee);
        tv_marquee.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_marquee) {
            bPause = !bPause;
            if (bPause) {
                tv_marquee.setFocusable(false);
                tv_marquee.setFocusableInTouchMode(false);
            } else {
                tv_marquee.setFocusable(true);
                tv_marquee.setFocusableInTouchMode(true);
            }
        }
    }
}
时间: 2024-08-06 07:55:36

关于跑马灯的体会的相关文章

(四)开关控制的 跑马灯 以及流水灯 电路图以及程序

电路图: 目的: K1  开始跑马灯 左->右 K2  停止 K3   跑马灯  右-> 左 K4   流水灯 参考程序: #include<reg52.h> #include<intrins.h> #define uchar8 unsigned char #define uint16 unsigned int #define LED P1 sbit key1=P2^0; sbit key2=P2^1; sbit key3=P2^2; sbit key4=P2^3; /

android ellipsize的使用及实现跑马灯效果总结

参考资料: http://blog.csdn.net/huiwolf2008/article/details/7901084 http://www.cnblogs.com/Gaojiecai/archive/2013/06/18/3142783.html 在TextView 和 EditText中,可以使用ellipsize来设置文字溢出隐藏,如:“一段很长的文本...” 用法如下: 在xml中 android:ellipsize = "end" 省略号在结尾 android:elli

Android仿京东首页轮播文字(又名垂直跑马灯)

Android仿京东首页轮播文字(又名垂直跑马灯) 京东客户端的轮播文字效果: 本次要实现的只是后面滚动的文字(前面的用ImageView或者TextView实现即可),看一下实现的效果 实现思路 上图只是一个大概的思路,要实现还需要完善更多的细节,下面会一步步的来实现这个效果: 1.封装数据源:从图上可以看到,轮播的文字是分为两个部分的,暂且把它们分别叫做前缀和内容,而且实际的使用过程中点击轮播图肯定是需要跳转页面的,而且大部分应该是WebView,不妨我们就设置点击时候需要获取的内容就是一个

js简单跑马灯案例

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>跑马灯</title> <style type="text/css"> *{ margin: 0; padding: 0; } #bian{ width: 300px; height: 300px; margin:0 auto

跑马灯《此方法为优化方法,内容不会有闪动效果》

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>跑马灯</title> //css部分 <style type="text/css"> #box { height: 30px; width: 800px; line-height: 30px; background-color:

android 跑马灯

1.在TextView中实现我们的走马灯效果,需要两个属性android:singleLine="true",以及android:ellipsize="marquee": 2.跑马灯效果需要TextVIew获得当前的焦点(focus).然而对于TextView这个控件来说,他的默认的Clickable,LongClickable,Focusable, FocusableInTouchMode这四个属性的值都是false,所以跑马灯效果也就不会出来了,即使你用手触摸T

原生js实现跑马灯抽奖效果

目前好多的微信活动都有一些抽奖活动,其中就有跑马灯. <!DOCTYPE html> <html> <head> <title>跑马灯效果</title> <style> table .pao{ border:1px solid #e5e5e5; padding:10px 20px; } table .on{ border-color:red; color:red; } </style> <script> wi

Android TextView 横向滚动(跑马灯效果)

Android TextView 中当文字比较多时希望它横向滚动显示,下面是一种亲测可行的方法. 效果图: 1.自定义TextView,重写isFocused()方法返回true,让自定义TextView一直处于获取焦点状态. package com.example.shen.marqueedemo; import android.content.Context; import android.util.AttributeSet; import android.widget.TextView;

Android textview 跑马灯 要加的属性

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@android:color/white"  android:ellipsize="marquee"  android:focusable="true" android:singleLine = &q