1. TextView mit Schatten
①. android:shadowColor="@color/black"
legt die Schattenfarbe fest und muss mit ShadowRadius verwendet werden
②. android:shadowRadius="3.0"
legt den Schattenunschärfegrad fest. Wenn Sie ihn auf 0,1 setzen, wird die Schriftfarbe geändert. Das ist es Es wird empfohlen, 3.0 einzustellen
③. android:shadowDx="10"
legt den Versatz des Schattens in horizontaler Richtung fest, die Abszissenposition, an der der Schatten in horizontaler Richtung beginnt
④, android:shadowDy="10"
legt den Versatz des Schattens fest in vertikaler Richtung die Ordinatenposition, an der der Schatten in vertikaler Richtung beginnt. Position
Beispiel:
<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 mit Marquee-Effekt
①, der Inhalt von android:singleLine="true"
wird in Zeile
② angezeigt, android:focusable="true" gibt an
, ob er den Fokus erhalten kann
③, android:focusableInTouchMode="true"
steuert, ob die Ansicht im Touch-Modus den Fokus erhalten kann
④, android:ellipsize=
Wo fügt ausgelassenen Text⑤ hinzu
, android:marqueeRepeatLimit="marquee_forever"
Wiederholungszeiten der Untertitelanimation
Implementierungsmethode 1: Erstellen Sie eine neue Textansicht, die AppCompatTextView erbt und die Methode isFocused() überschreibt
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;
}
}
Benutzerdefinierte Ansichten in XML verwenden:
<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"/>
Implementierungsmethode 2: AppCompatTextView der XML-Layoutdatei hinzufügen
<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>