Android移动应用开发之TextView实现阴影跑马灯文字效果_android studio textview阴影

注意不要出现中文
这里Android选择5.0说可以支持大概98.8%的设备,蛮多了。
点击finish完成创建

然后他会自己下载配置文件,需要联网耐心等待。

下载完成后
在这里插入图片描述
点击project选择project可以展现工程的全部文件

点击Android就展现
Android目录下的文件
在这里插入图片描述

配置文件简介

##
主要用户来放需要的java类

在这里插入图片描述
layout放置布局文件

在这里插入图片描述
values放颜色、文字、样式等配置文件。

阴影走马灯文字

values/string.xml

配置文字

<resources>
    <string name="app\_name">Hunter World</string>
    <string name="tv\_one">ICY Hunter ICY Hunter ICY Hunter ICY Hunter</string>
</resources>

values/colors.xml

配置颜色

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="purple\_200">#FFBB86FC</color>
    <color name="purple\_500">#FF6200EE</color>
    <color name="purple\_700">#FF3700B3</color>
    <color name="teal\_200">#FF03DAC5</color>
    <color name="teal\_700">#FF018786</color>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
</resources>

layout/activity_main.xml

配置布局文件

<?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:id="@+id/tv\_one"
 android:layout\_width="match\_parent"
 android:layout\_height="282dp"
 android:text="@string/tv\_one"
 android:textColor="@color/black"
 android:textStyle="normal"
 android:textSize="100sp"
 android:background="@color/purple\_200"
 android:layout\_gravity="center\_vertical"
 android:shadowColor="@color/purple\_700"
 android:shadowRadius="3.0"
 android:shadowDx="15.0"
 android:shadowDy="10.0"
 android:singleLine="true"
 android:ellipsize="marquee"
 android:marqueeRepeatLimit="marquee\_forever"
 android:focusable="true"
 android:focusableInTouchMode="true"
 android:clickable="true"
 >
        <requestFocus/>
    </TextView>


</LinearLayout>

在这里插入图片描述
点击运行app
然后虚拟机就会出现如下:
在这里插入图片描述
出现滚动的带阴影的跑马灯的效果。

法2

对代码进行如下添加和修改:

main/java

main/java的保重创建一个java类(MyTextView)
在这里插入图片描述
MyTextView:

package com.example.hunter;

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

import androidx.annotation.Nullable;

public class MyTextView extends TextView {

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

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

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

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


layout/activity_main.xml

用上自己写的类

<?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.example.hunter.MyTextView
        android:id="@+id/tv\_one"
        android:layout_width="match\_parent"
        android:layout_height="282dp"
        android:text="@string/tv\_one"
        android:textColor="@color/black"
        android:textStyle="normal"
        android:textSize="100sp"
        android:background="@color/purple\_200"
        android:layout_gravity="center\_vertical"
        android:shadowColor="@color/purple\_700"
        android:shadowRadius="3.0"
        android:shadowDx="15.0"
        android:shadowDy="10.0"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee\_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:clickable="true"
        />



</LinearLayout>

在这里插入图片描述
然后点击重新运行

出现一样的效果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值