I am currently writing an open source project that aims to port the famous Holo theme to previous versions of Android (since 1,6!!!)

我目前正在编写一个开源项目,旨在将着名的Holo主题移植到之前版本的Android(自1,6 !!!)

Everything works fine and I am really proud of my work, but the problem I am facing now is to get the ProgressBar totally looking like the ICS one.

一切都很好,我为我的工作感到自豪,但我现在面临的问题是让ProgressBar完全像ICS一样。

I used the same xml code than Android source: (progress_medium_holo.xml)

我使用了与Android源相同的xml代码:(progress_medium_holo.xml)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate
             android:drawable="@drawable/spinner_48_outer_holo"
             android:pivotX="50%"
             android:pivotY="50%"
             android:fromDegrees="0"
             android:toDegrees="1080" />
    </item>
    <item>
        <rotate
             android:drawable="@drawable/spinner_48_inner_holo"
             android:pivotX="50%"
             android:pivotY="50%"
             android:fromDegrees="720"
             android:toDegrees="0" />
    </item>
</layer-list>

With same png:

使用相同的png:

spinner_76_outer_holo.png and spinner_76_inner_holo.png

spinner_76_outer_holo.png和spinner_76_inner_holo.png

enter image description here white pic => enter image description here

白皮=>

But unfortunately, I only get one circle...

但不幸的是,我只得到一个圈...

If you don't understand what I mean, you can try this app on a pre-ICS device:

如果你不明白我的意思,你可以在pre-ICS设备上试试这个应用程序:

https://play.google.com/store/apps/details?id=com.WazaBe.HoloDemo

FULL SOURCE IS HERE: https://github.com/ChristopheVersieux/HoloEverywhere

完整的来源是这里:https://github.com/ChristopheVersieux/HoloEverywhere

Thank a lot for your help

非常感谢你的帮助

enter image description here

3 个解决方案

#1


12

Just found the answer here!

刚刚找到答案!

https://stackoverflow.com/a/8697806/327402

Very usefull post!

非常有用的帖子!

There is indeed a platform limitation, although it's not what you might think. The issue is that pre-API11, RotateDrawable had some crude code in it to require that the animation rotate clockwise by checking if toDegrees was greater than fromDegrees; if not, the two were forced equal to each other. If you modified your example to have the second item move in a forward direction (from 0 to 720, or even -720 to 0), both images would animate fine on all platforms; though I realize that defeats the purpose of what you're aiming for.

确实存在平台限制,尽管它不是您可能想到的。问题是,在API11之前,RotateDrawable中有一些原始代码要求动画顺时针旋转,检查toDegrees是否大于fromDegrees;如果没有,两人被迫相等。如果您修改了示例以使第二个项目向前移动(从0到720,甚至-720到0),则两个图像在所有平台上都可以正常显示;虽然我意识到这违背了你的目标。

Take a look at the cached version Google Codesearch has of RotateDrawable.inflate(), which is the 2.3 version of the method used to turn the XML into the object, and you'll see what I mean.

看一下Google Codesearch的缓存版本RotateDrawable.inflate(),它是用于将XML转换为对象的方法的2.3版本,你会明白我的意思。

RotateDrawable.java ...the offending code is around line 235...

RotateDrawable.java ......有问题的代码在第235行附近......

    float fromDegrees = a.getFloat(
            com.android.internal.R.styleable.RotateDrawable_fromDegrees, 0.0f);
    float toDegrees = a.getFloat(
            com.android.internal.R.styleable.RotateDrawable_toDegrees, 360.0f);

    toDegrees = Math.max(fromDegrees, toDegrees); //<--There's the culprit

This takes an XML block like the second item that you have there, and turns it into a RotateDrawable that ends up with the same value for fromDegrees and toDegrees (in your case, 720), causing the image to simply stand still. You can visible test this by setting the start value to some value not a multiple of 360 (like 765). You'll see that the image still does not animate, but is rotated to the initial coordinate.

这需要一个XML块,就像你在那里的第二个项目一样,并将它变成一个RotateDrawable,最终得到的值与fromDegrees和toDegrees(在你的情况下为720)相同,导致图像静止不动。您可以通过将起始值设置为某个值而不是360的倍数(如765)来显示测试结果。您将看到图像仍然没有动画,但会旋转到初始坐标。

This awkward check was removed in the Honeycomb/ICS sources, which is why you can do backwards rotation on those platforms. Also, it doesn't look like there is a way to set these values from Java code, so a custom RotateDrawableCompat may be in your future :)

在Honeycomb / ICS源中删除了这个尴尬的检查,这就是为什么你可以在这些平台上进行向后旋转的原因。此外,它看起来没有办法从Java代码设置这些值,所以自定义RotateDrawableCompat可能在你的未来:)

HTH

更多相关文章

  1. javaScript函数中执行C#代码中的函数
  2. POST json和图像到服务器android
  3. 反编译APK 得到JAVA代码和资源文件源码
  4. java.io.File vs java.nio.Files这是新代码中的首选?
  5. 拖动层的javasvript代码 十行代码即可写出兼容版拖动层
  6. 我无法让这个简单的ajax代码工作
  7. javascript实现拖动层效果代码(许愿墙)
  8. 牛客网Java刷题知识点之同步方法和同步代码块的区别(用synchroniz
  9. 在java自动生成hashCode代码问题? 请大神赐教

随机推荐

  1. android的SDK----google中的翻译
  2. Android(安卓)- Android(安卓)Architectu
  3. [Android]解决EditText设置成密码模式改
  4. Android(安卓)Studio 使用jdbc远程连接阿
  5. android 弹出软键盘将底部视图顶起问题
  6. Android四大组件——Activity生命周期详
  7. android访问服务器端上传及服务器端接收
  8. Android开发规范:Android(安卓)Studio规范
  9. android CTS测试
  10. 安卓入门教程(ps参考网络大部分教程,其中有