2017-06-07 15 views
4

私はKotlinにTextViewtextColorをアニメーション化する:Kotlinでargb color int valueを使用できませんか?

val animator = ObjectAnimator.ofInt(myTextView, "textColor", 0xFF8363FF, 0xFFC953BE) 

このエラーが発生します。

Error:(124, 43) None of the following functions can be called with the arguments supplied: 
public open fun <T : Any!> ofInt(target: TextView!, xProperty: Property<TextView!, Int!>!, yProperty: Property<TextView!, Int!>!, path: Path!): ObjectAnimator! defined in android.animation.ObjectAnimator 
public open fun <T : Any!> ofInt(target: TextView!, property: Property<TextView!, Int!>!, vararg values: Int): ObjectAnimator! defined in android.animation.ObjectAnimator 
public open fun ofInt(target: Any!, propertyName: String!, vararg values: Int): ObjectAnimator! defined in android.animation.ObjectAnimator 
public open fun ofInt(target: Any!, xPropertyName: String!, yPropertyName: String!, path: Path!): ObjectAnimator! defined in android.animation.ObjectAnimator 
public open fun ofInt(vararg values: Int): ValueAnimator! defined in android.animation.ObjectAnimator 

は、しかし、それはだ、値0xFF8363FF0xFFC953BEはKotlinにIntにキャストすることができないようですJavaのノーマル:

ObjectAnimator animator = ObjectAnimator.ofInt(myTextView, "textColor", 0xFF8363FF, 0xFFC953BE); 

アイデア?前もって感謝します。

答えて

9

0xFF8363FF(および0xFFC953BE)は、Intではなく、Longである。

明示的Intにそれらをキャストする必要があります。

val animator = ObjectAnimator.ofInt(myTextView, "textColor", 0xFF8363FF.toInt(), 0xFFC953BE.toInt()) 

ポイントは0xFFC953BEの数値が4291384254であるということですので、Long変数に格納する必要があります。しかし、ここでの上位ビットは符号ビットであり、負の数:-3583042を示し、Intに格納することができます。

それは2つの言語の違いです。

// Kotlin 
print(-0x80000000)    // >>> -2147483648 (fits into Int) 
print(0x80000000)    // >>> 2147483648 (does NOT fit into Int) 

// Java 
System.out.print(-0x80000000); // >>> -2147483648 (fits into Integer) 
System.out.print(0x80000000); // >>> -2147483648 (fits into Integer) 
+0

あなたはなぜそうなのかへの参照を追加することができます。Kotlinでは、のJavaには真実ではない負Intを示すために-記号を追加する必要がありますか? – tynn

+0

@ tynn私がその点を説明することができたかどうかはわかりません。 –

+0

それは、ありがとう、働く。 –

関連する問題