• TextView来实现跑马灯的效果


    <?xml version="1.0" encoding="utf-8"?>
    <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:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:singleLine="true"
            android:text="很多安卓软件的顶部或者底部有一些跑马灯文字,这个只需要在TextView代码里添加一些属性即可"
            android:textSize="18sp" />
    
    </LinearLayout>

    第二中方法

    package com.org.demo.demo;
    
    import android.content.Context;
    import android.graphics.Rect;
    import android.text.TextUtils;
    import android.util.AttributeSet;
    import android.view.ViewDebug.ExportedProperty;
    import android.widget.TextView;
    
    public class MarqueeTextView extends TextView {
        public MarqueeTextView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            setFocusable(true);
            setFocusableInTouchMode(true);
            setSingleLine();
            setEllipsize(TextUtils.TruncateAt.MARQUEE);
        }
    
        public MarqueeTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
            setFocusable(true);
            setFocusableInTouchMode(true);
            setSingleLine();
            setEllipsize(TextUtils.TruncateAt.MARQUEE);
        }
    
        public MarqueeTextView(Context context) {
            this(context, null);
        }
    
        @Override
        protected void onFocusChanged(boolean focused, int direction,
                Rect previouslyFocusedRect) {
            if (focused)
                super.onFocusChanged(focused, direction, previouslyFocusedRect);
        }
    
        @Override
        public void onWindowFocusChanged(boolean hasWindowFocus) {
            if (hasWindowFocus)
                super.onWindowFocusChanged(hasWindowFocus);
        }
    
        @Override
        @ExportedProperty(category = "focus")
        public boolean isFocused() {
            return true;
        }
    }
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        
    
        <com.org.demo.demo.MarqueeTextView
            android:layout_marginTop="20dp"
            android:id="@+id/tv_search_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="很多安卓软件的顶部或者底部有一些跑马灯文字,这个只需要在TextView代码里添加一些属性即可"
            android:textColor="#000"
            android:textSize="13sp" />
    
    </LinearLayout>

     在eclipse中常用的快捷键

    Ctrl+Alt+↓ 复制当前行到下一行(复制增加)

    Ctrl+Q 定位到最后编辑的地方

    Ctrl+T 快速显示当前类的继承结构

    Alt+Shift+L 抽取本地变量( 可以直接把一些魔法数字和字符串抽取成一个变量,尤其是多处调用的时候)

    Java编辑器 格式化 Ctrl+Shift+F

    ctrl + shift + o 导包

    ctrl + shift + t 快速查找某个类

    先按ctrl + 2 ,再点L, 创建变量并命名

    ctrl + o , 在当前类中,快速查找某个方法

    ctrl + k, 向下查找某个字符串

     ctrl + shift + k, 向上查找某个字符串

    Alt+Shift+L 抽取本地变量( 可以直接把一些魔法数字和字符串抽取成一个变量,尤其是多处调用的时候)

     ctrl+y  反撤销

  • 相关阅读:
    第二次作业
    初学JAVA的 感想 尹鑫磊
    初学JAVA 感想
    《将博客搬至CSDN》
    JAVA中的几种内部类
    JAVA-静态变量与实体变量
    teacher页面的代码
    测试说明书的概述和摘要
    网站的概述
    html与xhtml的区别
  • 原文地址:https://www.cnblogs.com/wangfengdange/p/5019948.html
Copyright © 2020-2023  润新知