TranslateAnimation in Android with adjacent view - android

I have a view with TransaleAnimation which works very fine. The problem is view has a android:layout_toRightOf="#id/iv_hook" to an ImageView which doesn't animate with view. Is there any way to achieve this?

The ImageView is for show/hide. when the view slides out i want 'Show' image to display.
Try something like this:
// yourImageView is hidden => its visibility is View.GONE
// animate your view with translation => slide out effect
viewToAnimate.animate().translationX(newTranslationX).setDuration(duration).withEndAction(new Runnable() {
#Override
public void run() {
// now, as the animation has just finished, we want to show the image
yourImageView.setVisibility(View.VISIBLE);
}
}).start();

Related

Translate animation on views with position dependencies

I am running into an issue where I have a header view that I would like to translate in and out of visibility--using translate animation--that is positioned directly above the main content view. To illustrate what I mean, look at the image below. The blue section is the header, and the orange section is the main content.
Example code
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -rlInfoBar.getHeight());
animation.setFillAfter(true);
animation.setDuration(10000);
animation.setAnimationListener(new TranslateAnimation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
rvItems.startAnimation(animation);
rlInfoBar.startAnimation(animation);
When I translate the blue section, even though the main section is declared "android:layout_below="#+id/" it remains in position. My idea was to then translate them both, however, when doing that the main content is shifted up but the bottom of the screen is also shifted up revealing the background of the parent view. How to solve this issue? Do I have to translate both views plus stretch the main content view or somehow anchor the main content view to the bottom of the screen?
Result of translating both views
Do I have to translate both views plus stretch the main content view or somehow anchor the main content view to the bottom of the screen?
Well, if you don't stretch the main content View then anchoring it to the bottom will cause a gap to appear at the top as soon as the header View moves up. So I think you'll need a set of animations (scale and translate) for it.
Or you use the Transition framework, in this case a ChangeBounds transition will do the job for both Views
View sceneRoot = <someViewGroupContainingBothViews>;
TransitionManager.beginDelayedTransition(sceneRoot, new ChangeBounds());
rlInfoBar.setY(<newY_CoordinateOfHeaderView>);

Android ScrollView loses clip on rotation animation

I'm using Rotate3dAnimation to flip a card view which contains a ScrollView. But during animation ScrollView loses a clip somehow so I see top and bottom of ScrollView content outside the card view (and ScrollView) bounds until animation is done.
Why is that and how to beat this behaviour?
This unfortunately happens due to the way the bounds for the ScrollView are calculated. It seems the bounds are not "rotated" along with the view.
One work around is to take a snapshot of each view - both the front and the back of the card - and then to animate between these snapshots above the actual views.
The code would look something like this:
firstView.setDrawingCacheEnabled(true);
firstAnimationView.setBackgroundDrawable(new BitmapDrawable(firstView.getDrawingCache()));
secondView.setDrawingCacheEnabled(true);
secondAnimationView.setBackgroundDrawable(new BitmapDrawable(secondView.getDrawingCache()));
Animation flipOutAnimation = createFlipOutAnimation();
flipOutAnimation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationEnd(Animation animation) {
firstAnimationView.setVisibility(View.GONE);
}
...
});
Animation flipInAnimation = createFlipInAnimation();
flipInAnimation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationEnd(Animation animation) {
animationBackgroundView.setVisibility(View.GONE);
secondAnimationView.setVisibility(View.GONE);
}
...
});
firstAnimationView.startAnimation(flipOutAnimation);
secondAnimationView.startAnimation(flipInAnimation);
animationBackgroundView.setVisibility(View.VISIBLE);
firstAnimationView.setVisibility(View.VISIBLE);
secondAnimationView.setVisibility(View.VISIBLE);
For backwards compatible flip animations, I use http://genzeb.github.io/flip/

View.setVisibility(View.INVISIBLE) does not work for animated view

I have an activity that (when started) shows some coachmark views (All ImageButtons) on screen that indicate how the app should be used (function of certain buttons, swipe behaviour, etc). A fade out animation is associated with each of these views that triggers after some predefined interval. This works as expected. However, I would like those marks to disappear earlier if the user interacts with the activity in a certain way. When these actions are triggered I cancel the animations and callsetVisibility(View.INVISIBLE); on the coachmark views. However, the visibility of the view does not change. I have experimented with other techniques - removing the view from the parent and setting alpha to 0 and these work fine but altering view visibility does nothing.
The code that sets up the coachmark looks as follows:
private void animateCoachmark(int id) {
AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
final View view = findViewById(id);
animation.setStartOffset(10000);
animation.setDuration(500);
animation.setAnimationListener(new AnimationListenerBase(null) {
#Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.INVISIBLE);
}
});
view.startAnimation(animation);
coachmarkViews.add(view);
}
The problematic code to change visiblity:
for (final View coachmarkView : coachmarkViews) {
Animation animation = coachmarkView.getAnimation();
if (animation != null) {
animation.cancel();
}
coachmarkView.setVisibility(View.INVISIBLE);
}
This issue seems to be that changes to visibility are not honoured as long as an animation is associated with a view even if the animation has been cancelled. Altering my cleanup code to first set the animation on the view to null allows the view to disappear as expected.
for (final View coachmarkView : coachmarkViews) {
Animation animation = coachmarkView.getAnimation();
if (animation != null) {
animation.cancel();
coachmarkView.setAnimation(null);
}
coachmarkView.setVisibility(View.INVISIBLE);
}

Multi-View Android ScrollView scrollTo Popover not working

My app opens up in View A. In View B, I have made a custom popover who's view contains:
LinearLayout
ScrollView
LinearLayout1
LinearLayout2
.
.
.
LinearLayoutN
What I wish to do is From View A, Move Into View B having set the Vertical Scroll position to a specific LinearLayout from the ScrollView within the Popup.
I have the scrollview being assigned in code to a variable and
variable.scrollTo
is NOT working.
I have also tried to put
sView.post(new Runnable() {
#Override
public void run() {
sView.scrollTo(0, myNum);
}
});
within the routine I run to setup View B, Tried it Outside in the OnCreate routine. Nothing seems to be working to scroll the ScrollView.
The
sView.post(new Runnable() {
#Override
public void run() {
sView.scrollTo(0, scrollYPos);
}
});
was EXTREMELY useful, however its placement was even more important. Do to the scrollview being inside of a popover view, the code above actually had to be placed AFTER the code that truly brought that popover onto screen.

How can draw frame by frame animation on image view, both visible simultaneously in Android?

I want to draw animation on image view and the image position is changing on run time if user successfully tap on the image then an animation is to be draw.Here is my code
public void enter() { //To enter in to animation
setBackgroundResource(R.anim.dhakkan_animation);
frameByframe_animation = (AnimationDrawable) getBackground();
frameByframe_animation.start();
frameByframe_animation.setOneShot(true);
}
#Override
public void exit() {
//when exit from Animation
frameByframe_animation.stop();
frameByframe_animation.setVisible(false, false);
}
the problem is that when animation darws my image of image view get invisible. According to my requirement i have to show both simultaneously in background an image(image of image view) and in foreground animation play.Plese help me im totally frustated.
If you want to show imageView, when your animation goes, just do it in *.xml:
<ImageView android:id=#+id/s210 ..... android:src="#drawable/s210 />

Categories

Resources