Facebook のリバウンド ライブラリを使用して、チャット ヘッドの実装で見られる跳ねるアニメーションを再現しています。問題は、ほとんどの場合、アニメーションが途切れることです。いくつかの写真がこれをよりよく説明します。バターのように滑らかなチャットヘッドのアニメーションは次のとおりです。
そして、これが私の試みです(白のアニメーションがView
ほぼすべてのフレームをスキップすることに注意してください):
たまにスムーズに動作します:
以下は私が現在使用しているコードです (すぐにセットアップしたい場合は、プロジェクト全体がGithubにあります)。これは、ハードウェアアクセラレーションが正しく有効になっていないことに関係していると思いView
ます。Spring
myには 2 つの s がありSpringSystem
、1 つは「バブル」(Android アイコン) 用で、もう 1 つはコンテンツ (View
バブルをタップすると表示される白) 用です。この問題を解決する方法についての助けをいただければ幸いです。ありがとう。
AndroidManifest.xml
:
<application android:hardwareAccelerated="true" ...>
...
</application>
AppService.java
:
// the following code is in AppService#onCreate()
// AppService extends android.app.Service
// full code at https://github.com/vickychijwani/BubbleNote
mContent.setLayerType(View.LAYER_TYPE_HARDWARE, null);
final Spring bubbleSpring = system.createSpring();
bubbleSpring.setCurrentValue(1.0);
bubbleSpring.addListener(new SpringListener() {
@Override
public void onSpringUpdate(Spring spring) {
float value = (float) spring.getCurrentValue();
params.x = (int) (mPos[0] * value);
params.y = (int) (mPos[1] * value);
mWindowManager.updateViewLayout(mBubble, params);
// fire the second animation when this one is about to end
if (spring.isOvershooting() && contentSpring.isAtRest()) {
contentSpring.setEndValue(1.0);
}
}
// ...
});
final Spring contentSpring = system.createSpring();
contentSpring.setCurrentValue(0.0);
contentSpring.addListener(new SpringListener() {
@Override
public void onSpringUpdate(Spring spring) {
// always prints false?!
Log.d(TAG, "hardware acc = " + mContent.isHardwareAccelerated());
float value = (float) spring.getCurrentValue();
// clamping is required to prevent flicker
float clampedValue = Math.min(Math.max(value, 0.0f), 1.0f);
mContent.setScaleX(value);
mContent.setScaleY(value);
mContent.setAlpha(clampedValue);
}
// ...
});