animate a view from a particular point to fill whole screen and the re size it back to that point

I Know how to animate a view to whole screen and animate back to its original size. here is the link to do this Re sizing through animation

But the problem is that this technique works only when if my view is place at the start of the screen.

What i want is that if my view of height and width (50,50) is placed in center of screen below some button and i click that view it should animate to fill the whole screen and when clicked again it animates back to its original size (50,50)

Answers


If you're using LinearLayout, try to set AnimationListener for this animation and toggle the visibility of the button appropriately. Set button's visibility to View.GONE onAnimationStart when 'expanding' view and to View.VISIBLE onAnimationEnd when 'collapsing' it. Using RelativeLayout can be the solution for this problem too.

For animation:

public class ExpandCollapseViewAnimation extends Animation {
int targetWidth;
int targetHeight;
int initialWidth;
int initialHeight; 
boolean expand;
View view;

public ExpandCollapseViewAnimation(View view, int targetWidth, int targetHeight ,boolean expand) {
    this.view = view;
    this.targetWidth = targetWidth;
    this.targetHeight = targetHeight;
    this.initialWidth = view.getWidth();
    this.initialHeight = view.getHeight();
    this.expand = expand;
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    int newWidth, newHeight;
    if (expand) {
        newWidth = this.initialWidth
                + (int) ((this.targetWidth - this.initialWidth) * interpolatedTime);
        newHeight = this.initialHeight
                + (int) ((this.targetHeight - this.initialHeight) * interpolatedTime);
    } else {
        newWidth = this.initialWidth
                - (int) ((this.initialWidth - this.targetWidth) * interpolatedTime);
        newHeight = this.initialHeight
                - (int) ((this.initialHeight - this.targetHeight) * interpolatedTime);
    }

    view.getLayoutParams().width = newWidth;
    view.getLayoutParams().height = newHeight;
    view.requestLayout();
}

@Override
public void initialize(int width, int height, int parentWidth,
        int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
}

@Override
public boolean willChangeBounds() {
    return true;
}

}

And layout XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button android:id="@+id/btn"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_gravity="center_horizontal"
    android:text="Test"/>


<View android:id="@+id/centered_view"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:clickable="true"
    android:layout_gravity="center_horizontal"
    android:background="#FF0000"/>

</LinearLayout>

This code works:

animatedView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!expand) expandView();
            else collapseView();
        }
    });

private void expandView() {
    expand = true;
    animatedView.clearAnimation();
    Display display = this.getWindowManager().getDefaultDisplay();
    int maxWidth = display.getWidth();
    int maxHeight = display.getHeight();
    ExpandCollapseViewAnimation animation = new ExpandCollapseViewAnimation(animatedView, maxWidth,maxHeight, expand);
    animation.setDuration(500);
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            btn.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {    
        }

        @Override
        public void onAnimationEnd(Animation animation) {
        }
    });
    animatedView.startAnimation(animation);
    animatedView.invalidate();
}

private void collapseView() {
    expand = false;
    animatedView.clearAnimation();
    ExpandCollapseViewAnimation animation = new ExpandCollapseViewAnimation(
            animatedView, dpToPx(this, 50),dpToPx(this, 50), expand);
    animation.setDuration(500);
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            btn.setVisibility(View.VISIBLE);
        }
    });
    animatedView.startAnimation(animation);
    animatedView.invalidate();
}

Need Your Help

error: -ld returned 1 exit status.

c linux

#include &lt;stdio.h&gt;

Get title Attribute of image in variable PHP

php html arrays function dom

How can I get the title from the image tag?