zoukankan      html  css  js  c++  java
  • 关于跑马灯的体会

    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);
                }
            }
        }
    }
  • 相关阅读:
    泰国行记三:PP岛三天的休闲时光
    泰国行记二:普吉印象
    177. Nth Highest Salary
    176. Second Highest Salary
    175. Combine Two Tables
    Regular Expression Matching
    斐波那契数列
    用两个栈实现队列
    二叉树的下一个节点
    重建二叉树
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/7368322.html
Copyright © 2011-2022 走看看