android - シャドウ効果とマーキー効果 Textview

1. 影付きの TextView

①. android:shadowColor="@color/black" は
影の色を設定し、shadowRadius と一緒に使用する必要があります
②. android:shadowRadius="3.0" は
影のぼかしレベルを設定します. 0.1 に設定するとフォントの色が変わります。 3.0を設定することを推奨します
③. android:shadowDx="10" は
水平方向の影のオフセット、水平方向の影が始まる横座標の位置を設定します
④、android:shadowDy="10" は
影のオフセットを設定します垂直方向では、垂直方向で影が開始される縦座標位置

例:

    <androidx.appcompat.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:shadowRadius="3.0"
        android:shadowColor="@color/black"
        android:shadowDx="10"
        android:shadowDy="10"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

2. マーキー効果のある TextView

①、android:singleLine="true" の
内容が行に表示されます
。 ②、android:focusable="true"
がフォーカスを取得できるかどうかを決定します。
③、android:focusableInTouchMode="true" は、
タッチ モードでビューがフォーカスを取得できるかどうかを制御します
。 ④、 android:ellipsize= "marquee" は省略されたテキストを
どこに追加しますか⑤
、 android:marqueeRepeatLimit="marquee_forever"
字幕アニメーションの繰り返し回数

実装方法 1: AppCompatTextView を継承し、isFocused() メソッドをオーバーライドする新しいテキストビューを作成する

public class CustomTextView extends AppCompatTextView {
    
    

    public CustomTextView(@NonNull Context context) {
    
    
        super(context);
    }
    public CustomTextView(@NonNull Context context, @Nullable AttributeSet attrs) {
    
    
        super(context, attrs);
    }
    public CustomTextView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    
    
        super(context, attrs, defStyleAttr);
    }
    @Override
    public boolean isFocused() {
    
    
        return true;
    }
}

XML でカスタム ビューを使用します。

  <com.lxd.xdplayer.CustomTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World!"
        android:singleLine="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

実装方法2:XMLレイアウトファイルのAppCompatTextViewに追加

    <androidx.appcompat.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World!"
        android:singleLine="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        <requestFocus/>
    </androidx.appcompat.widget.AppCompatTextView>

おすすめ

転載: blog.csdn.net/qq_26554909/article/details/134459429