android学习笔记(二)第一个androin程序并实现跑马灯

一、在Android studio创建一个空的Android项目

在这里插入图片描述

二、编写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">
    <!--
        match_parent:容器的宽度
        wrap_content:根据内容来分配宽度
    -->
    <TextView
        android:id="@+id/tv_one"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="@string/tv_one"
        android:textColor="@color/teal_200"
        android:textStyle="bold"
        android:textSize="30dp"
        android:background="@color/purple_200"
        android:gravity="center"
        android:shadowColor="@color/purple_500"
        android:shadowRadius="0.1"
        android:shadowDx="3.0"
        android:focusableInTouchMode="true"
        android:shadowDy="3.0"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever">
    </TextView>
</LinearLayout>

在strings.xml下创建自定义文本
在这里插入图片描述

三、实现跑马灯的三种方式

先在TextView里添加三个属性:

  		android:singleLine="true" //不出现换行
        android:ellipsize="marquee"	//跑马灯属性
        android:marqueeRepeatLimit="marquee_forever"	//跑多少次的设定

方式1:
  在属性下添加 android:clickable="true"属性;

在这里插入图片描述

此方法需要主动去点TextView的内容,不方便!

方式2
  创建一个自定义的类使文本聚焦:
在这里插入图片描述

package com.example.androin1;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

import androidx.annotation.Nullable;

public class MyTestView extends TextView {

    public MyTestView(Context context) {
        super(context);
    }

    public MyTestView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyTestView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean isFocused() {
        return true;
    }
}

  然后修改TextView的名字:
在这里插入图片描述
修改名字是你写的类的路径+类名;
然后运行即可!

方式3(最简便的一种):

   直接在TextView里加一个即可,不需要别的操作!
在这里插入图片描述

注:内容简单,继续努力!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值