How to make a rectangle scale twice in android - android-animation

I have a rectangle that i know how to scale through animation in xml like this
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="2000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="100%"
android:toXScale="1.0"
android:toYScale="5.0" />
</set>
But the problem is even if I do this
public void practice(View view) {
View test = (View) findViewById(R.id.view1);
Animation scale = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.scale);
scale.setFillAfter(true);
scale.setFillBefore(true);
test.startAnimation(scale);
}
It will only allow me to grow a rectangle once and stay that scale only once. I want it in such that everytime I grow the rectangle, i make scale it again to a bigger size. How do i do that?

I am not sure I understand the question. However, I think the problem is that you declare the View within the practice function. This means it will reload each time and then scale. I think you want to declare the view outside the function (eg. in onCreate() or onCreateView()) and call practice(test) where you need it.

Related

Fragment Transition Animation

I am trying to animate 2 Fragments [Splash Fragment , Fragment 1]
While the transition there is a white blank screen for small milli Secs which should not be there
The code of Animation Resource File : -
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%" android:toXDelta= "0%" android:duration = "250"/>
</set>
This file I was adding in Navigation file for a action in the field of enter Anim
The navigation from my splash Fragment is as follows:
Handler().postDelayed({findNavController().navigate(R.id.action_splashScreen_to_onBording)},3000)
As mentioned the basic problem is while the Transition there is a small window of few milli secs where a white screen is appearing and spoiling the view . How do I remove it?
Thanks in advance
As I can not make sense out of you animation file which is fromYDelta, toXDelta, which are to opposite things. So, I am considering you have meant fromYDelta toYDelta, which will make the fragment slide from bottom to top.
Now, about the answer. When setting up animations on navigation you have to create an exit animation as well as enter animation. Otherwise you'll face this problem of white screen.
So, what you can do is add the below animation as exit animation.
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%" android:toYDelta= "-100%" android:duration = "450"/>
</set>
It will make the splash fragment slide upwards as well, but slower than the fragment1. And empty white screen will not be shown.

Animating UIVisualEffectView Blur Radius?

As the title says it, is there a way to animate a UIVisualEffectView's blur radius? I have a dynamic background behind the view so the ImageEffects addition can't be used... The only thing that can do this as far as I know is to animate the opacity but iOS complains saying that doing that breaks the EffectView so it definitely seems like a bad idea... Any help would be gladly appreciated.
The answer is yes. Here's an example for animating from no blur -> blur:
// When creating your view...
let blurView = UIVisualEffectView()
// Later, when you want to animate...
UIView.animateWithDuration(1.0) { () -> Void in
blurView.effect = UIBlurEffect(style: .Dark)
}
This will animate the blur radius from zero (totally transparent, or rather - no blur effect at all) to the default radius (fully blurred) over the duration of one second. And to do the reverse animation:
UIView.animateWithDuration(1.0) { () -> Void in
blurView.effect = nil
}
The resulting animations transform the blur radius smoothly, even though you're actually adding/removing the blur effect entirely - UIKit just knows what to do behind the scenes.
Note that this wasn't always possible: Until recently (not sure when), a UIVisualEffectView had to be initialized with a UIVisualEffect, and the effect property was read-only. Now, effect is both optional and read/write (though the documentation isn't updated...), and UIVisualEffectView includes an empty initializer, enabling us to perform these animations.
The only restriction is that you cannot manually assign a custom blur radius to a UIVisualEffectView - you can only animate between 'no blur' and 'fully blurred'.
EDIT: In case anybody is interested, I've created a subclass of UIVisualEffectView that gives you full control over blur radius. The caveat is that it uses a private UIKit API, so you probably shouldn't submit apps for review using it. However, it's still interesting and useful for prototypes or internal applications:
https://github.com/collinhundley/APCustomBlurView

LeadBolt Interstitial ad - I can not remove black background

I use interstitial leadbolt ad in my app. Problem that it looks ugly.
there is screenshot
alt text
advert_activity_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg_result_activity"
>
</FrameLayout>
AdvertActivity.java
import android.os.Bundle;
import com.Leadbolt.AdController;
import com.alpha_aps.very_hard_game.util.MyActivity;
public class AdvertActivity extends MyActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.advert_activity_layout);
AdController myController = new AdController(this, Config.leadBoltInterstitialId);
myController.loadAd();
}
}
I tried use some different layout such as RelativeLayout, FrameLayout, LinearLayout - no result.
Also I tried play with leadbolt ad settings - use different kind of interstitials - no result also.
So questions are:
Why interstitial looks with black background?
How can I remove this background?
Thanks to all.
When you create a new ad make sure to check to appearance tab at the top. There is a section here for background color. For a transparent background make sure that this field is empty.
Once an ad has been created I think that the appearance can not be changed so you may need to create a new one.
Alternatively you could set the Overlap Opacity to 100% so that the whole screen around the ad is also black. The field is also located on the appearance tab of your ad creation screen.
I updated to the last Leadbolt SDK
and black background disappear, I do not why.

animation for zoom in and zoom out in android for imageview

How do i set zoom in and zoom out when click on imageview?I want my program to react when user click on imageview must get large to some extent and can move imageview on that screen and sometime it reduce the size along when it move on touch anywhere on the screen .when click again is go resume original size what do i do?
As far as I know there are two ways.
The first way:
Make a new folder in res called 'anim'. Than make a xml file inside, for example zoomin.xml. Afterwards put the following code inside.
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:toXScale="5"
android:fromYScale="1"
android:toYScale="5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:fillAfter="true">
</scale>
Make another one for zoom out, but with reversed values.
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="5"
android:toXScale="1"
android:fromYScale="5"
android:toYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:fillAfter="true">
</scale>
You can change the values according to your needs. I think that they are self-explanatory.
And now in your java code.
ImageView imageView = (imageView)findViewById(R.id.yourImageViewId);
Animation zoomin = AnimationUtils.loadAnimation(this, R.anim.zoomin);
Animation zoomout = AnimationUtils.loadAnimation(this, R.anim.zoomout);
imageView.setAnimation(zoomin);
imageView.setAnimation(zoomout);
Now you only need to keep track which is the current state. And for each state execute this lines of codes:
imageView.startAnimation(zoomin);
and
imageView.startAnimation(zoomout);
For example:
imageView.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
if(!pressed) {
v.startAnimation(zoomin);
pressed = !pressed;
} else {
v.startAnimation(zoomout);
pressed = !pressed;
}
}
});
The other way is described here : http://developer.android.com/training/animation/zoom.html.
You can make this by following this guide easily
http://developer.android.com/training/animation/zoom.html
shortly you should use third imageview which is invisible when the user touches any imageview you want, you can display it by using animation in the imageview which is invisible.

Auto-resize content of a new AIR Window

AIR's spark.components.WindowedApplication would resize its contents automatically as I manually stretch window bounds or maximize/restore it. But spark.components.Window class does not provide such functionality 'out of the box': the contents of the Window don't change their size as I stretch/maximize/restore the window, when the corresponding spark.components.Window.nativeWindow instance does resize its bounds. My AIR application is required to open multiple windows, and resizable ones. How can I make them automatically resize their contents to match the nativeWindow bounds?
Assuming you mean the spark.components.Window, this is based on the skinnablecontainer so there shouldn't be anything preventing you from using a percentbased layout / constraint.
<s:Window xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%" height="100%">
Other methods for manually handling this sort of thing include listening for the ResizeEvent coming from the stage.
The solution is to listen to a RESIZE event coming from the NativeWindow and then to manually set stageWidth and stageHeight on Window's stage instance. See code below.
override public function open(openWindowActive:Boolean=true):void {
super.open(openWindowActive);
if (nativeWindow) {
chromeWidth = nativeWindow.width - this.width;
chromeHeight = nativeWindow.height - this.height;
nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, onNativeResize);
}
}
private function onNativeResize(event:NativeWindowBoundsEvent):void {
stage.stageWidth = event.afterBounds.width - chromeWidth;
stage.stageHeight = event.afterBounds.height - chromeHeight;
}