SK9*_*SK9 5 animation android scroll textview
我有一个带有以下XML属性的文本视图:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dip"
android:maxLines="1"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="1"
android:textColor="@android:color/black"
android:id="@+id/ticker"
/>
Run Code Online (Sandbox Code Playgroud)
我希望能够设置水平滚动速率,使其略快于默认值.我该怎么做(用XML格式)?
提前感谢你.
我不认为您可以为此目的在XML中设置属性.
这对你来说可能有点矫枉过正,但是请查看这个针对Android的自定义扩展选框,所有设置都可以在编码部分进行自定义,你需要使用动画的setDuration来实现你想要的速度.
这是我如何做到的,它很脏,但它完成了工作,直到它们唤醒并使其可配置!
你能相信在Marquee私有静态内部类中有一个" // TODO添加一个配置它的选项 "!
protected void setMarqueeSpeed(TextView tv, float speed, boolean speedIsMultiplier) {
try {
Field f = tv.getClass().getDeclaredField("mMarquee");
f.setAccessible(true);
Object marquee = f.get(tv);
if (marquee != null) {
Field mf = marquee.getClass().getDeclaredField("mScrollUnit");
mf.setAccessible(true);
float newSpeed = speed;
if (speedIsMultiplier) {
newSpeed = mf.getFloat(marquee) * speed;
}
mf.setFloat(marquee, newSpeed);
Log.i(this.getClass().getSimpleName(), String.format("%s marquee speed set to %f", tv, newSpeed));
}
} catch (Exception e) {
// ignore, not implemented in current API level
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16176 次 |
最近记录: |