M
Madlip
Gast
Hey Community,
ich versuche ein FrameLayout zu zoomen, ähnlich wie es hier beschrieben ist: Zooming a View | Android Developers
Mein Problem ist das wenn die View das erste mal gezoomt wird alles ok ist, aber beim zweiten mal kommt die View von links-mittig zum center, default ist es von links unten in die mitte. Dabei hab ich beobachtet das die Werte für View.X, View.Y sowie die scale Werte andere sind.
Ich habe vom Code her ca das gleiche wie in link oben, einziger Unterschied, anstatt eines ImageView nutze ich ein FrameLayout, des weiteren hab ich die minimize Methode (in der OnClickMethode von der ExpandView im Bsp) ausgelagert.
Nun schaut das ganze so aus:
Die startBounds Variable ist Global weil ich die in der minimize Methode nochmal brauche:
if i debug this whole process i can see that the method getGlobalVisibleRect from the method zoomViewFromThumb give me another value.
Beim debuggen ist mir aufgefallen das in der Methode
Beim ersten mal die Parameter wie folgt sind: 0 und -60 und beim zweiten mal sind sie dann: 15 and 360.
i have no idea why thats happen.
irgendjemand eine Idee?
Grüße Mad
PS: In der Android Version 4.0 funktioniert es, dort ist das Ergebnis wie gewünscht aber in der Android Version 4.1.2 klappt es nicht
ich versuche ein FrameLayout zu zoomen, ähnlich wie es hier beschrieben ist: Zooming a View | Android Developers
Mein Problem ist das wenn die View das erste mal gezoomt wird alles ok ist, aber beim zweiten mal kommt die View von links-mittig zum center, default ist es von links unten in die mitte. Dabei hab ich beobachtet das die Werte für View.X, View.Y sowie die scale Werte andere sind.
Ich habe vom Code her ca das gleiche wie in link oben, einziger Unterschied, anstatt eines ImageView nutze ich ein FrameLayout, des weiteren hab ich die minimize Methode (in der OnClickMethode von der ExpandView im Bsp) ausgelagert.
Nun schaut das ganze so aus:
Code:
private void zoomImageFromThumb(final View thumbView) {
if (mCurrentAnimator != null) {
mCurrentAnimator.cancel();
}
// here i building my custome layout
startBounds = new Rect();
final Rect finalBounds = new Rect();
final Point globalOffset = new Point();
thumbView.getGlobalVisibleRect(startBounds);
findViewById(R.id.container)
.getGlobalVisibleRect(finalBounds, globalOffset);
startBounds.offset(-globalOffset.x, -globalOffset.y);
finalBounds.offset(-globalOffset.x + 15, -globalOffset.y + 60);
float startScale;
if ((float) finalBounds.width() / finalBounds.height()
> (float) startBounds.width() / startBounds.height()) {
startScale = (float) startBounds.height() / finalBounds.height();
float startWidth = startScale * finalBounds.width();
float deltaWidth = (startWidth - startBounds.width()) / 2;
startBounds.left -= deltaWidth;
startBounds.right += deltaWidth;
} else {
startScale = (float) startBounds.width() / finalBounds.width();
float startHeight = startScale * finalBounds.height();
float deltaHeight = (startHeight - startBounds.height()) / 2;
startBounds.top -= deltaHeight;
startBounds.bottom += deltaHeight;
}
thumbView.setAlpha(0f);
expandedImageView.setVisibility(View.VISIBLE);
expandedImageView.setPivotX(0f);
expandedImageView.setPivotY(0f);
AnimatorSet set = new AnimatorSet();
set
.play(ObjectAnimator.ofFloat(expandedImageView, View.X,
startBounds.left, finalBounds.left))
.with(ObjectAnimator.ofFloat(expandedImageView, View.Y,
startBounds.top, finalBounds.top))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X,
startScale, 1f)).with(ObjectAnimator.ofFloat(expandedImageView,
View.SCALE_Y, startScale, 1f));
set.setDuration(mShortAnimationDuration);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mCurrentAnimator = null;
}
@Override
public void onAnimationCancel(Animator animation) {
mCurrentAnimator = null;
}
});
set.start();
mCurrentAnimator = set;
}
Die startBounds Variable ist Global weil ich die in der minimize Methode nochmal brauche:
Code:
private void minimizeViewFromThumb(final View thumbView) {
if (mCurrentAnimator != null) {
mCurrentAnimator.cancel();
}
AnimatorSet set = new AnimatorSet();
set.play(ObjectAnimator
.ofFloat(expandedImageView, View.X, startBounds.left))
.with(ObjectAnimator
.ofFloat(expandedImageView,
View.Y,startBounds.top))
.with(ObjectAnimator
.ofFloat(expandedImageView,
View.SCALE_X, startScaleFinal))
.with(ObjectAnimator
.ofFloat(expandedImageView,
View.SCALE_Y, startScaleFinal));
set.setDuration(mShortAnimationDuration);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
thumbView.setAlpha(1f);
expandedImageView.setVisibility(View.GONE);
mCurrentAnimator = null;
}
@Override
public void onAnimationCancel(Animator animation) {
thumbView.setAlpha(1f);
expandedImageView.setVisibility(View.GONE);
mCurrentAnimator = null;
}
});
set.start();
mCurrentAnimator = set;
}
if i debug this whole process i can see that the method getGlobalVisibleRect from the method zoomViewFromThumb give me another value.
Beim debuggen ist mir aufgefallen das in der Methode
Code:
finalBounds.offset(-globalOffset.x, -globalOffset.y);
Beim ersten mal die Parameter wie folgt sind: 0 und -60 und beim zweiten mal sind sie dann: 15 and 360.
i have no idea why thats happen.
irgendjemand eine Idee?
Grüße Mad
PS: In der Android Version 4.0 funktioniert es, dort ist das Ergebnis wie gewünscht aber in der Android Version 4.1.2 klappt es nicht