Android 安卓:选框开始位置和改变速度

Android 安卓:选框开始位置和改变速度,android,marquee,Android,Marquee,我有这个代码创建一个字幕,我可以改变它的速度和启动时的位置激活?我写下了这些代码,当我点击按钮时,它会在中心启动字幕 <TextView android:id="@+id/mywidget" android:layout_width="fill_parent" android:textSize="20dp" android:layout_height="wrap_content" android:text="This is a test of mar

我有这个代码创建一个字幕,我可以改变它的速度和启动时的位置激活?我写下了这些代码,当我点击按钮时,它会在中心启动字幕

<TextView
    android:id="@+id/mywidget"
    android:layout_width="fill_parent"
    android:textSize="20dp"
    android:layout_height="wrap_content"
    android:text="This is a test of marquee on the text view in android."
    android:ellipsize="marquee"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:focusable="false"
    android:marqueeRepeatLimit="marquee_forever"
    android:textStyle="bold"
    android:shadowColor="#f5067e"
    android:textColor="#ff000d"
    android:shadowDx="0.0"
    android:shadowDy="0.0"
    android:shadowRadius="8"
    />

我也希望改变字幕的速度和开始位置。 我找到了速度的解决办法。 原职-

确保仅在tv.setText和tv.setSelectedtrue之后调用此方法。否则它将无法工作

public static void setMarqueeSpeed(TextView tv, float speed) {
    if (tv != null) {
        try {
            Field f = null;
            if (tv instanceof AppCompatTextView) {
                f = tv.getClass().getSuperclass().getDeclaredField("mMarquee");
            } else {
                f = tv.getClass().getDeclaredField("mMarquee");
            }
            if (f != null) {
                f.setAccessible(true);
                Object marquee = f.get(tv);
                if (marquee != null) {
                    String scrollSpeedFieldName = "mScrollUnit";
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        scrollSpeedFieldName = "mPixelsPerSecond";
                    }
                    Field mf = marquee.getClass().getDeclaredField(scrollSpeedFieldName);
                    mf.setAccessible(true);
                    mf.setFloat(marquee, speed);
                }
            } else {
                Logger.e("Marquee", "mMarquee object is null.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

我也希望改变字幕的速度和开始位置。 我找到了速度的解决办法。 原职-

确保仅在tv.setText和tv.setSelectedtrue之后调用此方法。否则它将无法工作

public static void setMarqueeSpeed(TextView tv, float speed) {
    if (tv != null) {
        try {
            Field f = null;
            if (tv instanceof AppCompatTextView) {
                f = tv.getClass().getSuperclass().getDeclaredField("mMarquee");
            } else {
                f = tv.getClass().getDeclaredField("mMarquee");
            }
            if (f != null) {
                f.setAccessible(true);
                Object marquee = f.get(tv);
                if (marquee != null) {
                    String scrollSpeedFieldName = "mScrollUnit";
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        scrollSpeedFieldName = "mPixelsPerSecond";
                    }
                    Field mf = marquee.getClass().getDeclaredField(scrollSpeedFieldName);
                    mf.setAccessible(true);
                    mf.setFloat(marquee, speed);
                }
            } else {
                Logger.e("Marquee", "mMarquee object is null.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}