I want to make text size bigger when I click on TextView and I have code like
/res/anim/scale_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.3"
android:toYScale="1.3" >
</scale>
</set>
and in code like
txt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Animation a = AnimationUtils.loadAnimation(SwipeActivity.this, R.anim.scale_up);
a.reset();
v.clearAnimation();
v.startAnimation(a);
}
});
and it scales but when it finishes scaling (500ms) it comes back on old size of font. How to prevent that, I want to stay doubled size ?
First off you could set the textsize to the TextView instad of using an animation. Animating it will make the text blurred.
eks:
textView.setTextSize(20);
The reason why the animation pops back to the original size is because you don´t use setFillAfter.
Animation a = AnimationUtils.loadAnimation(SwipeActivity.this, R.anim.scale_up);
a.setFillAfter(true);
v.startAnimation(a);
Related
I need to locate a click on one ImageView (image1) and then to set my second ImageView (image2) to the same position, and start a rotate animation on image2.
My animatiom works fine when i don't change image2 position.
When I want to change the position and start the animation together image2 is moving all over the screen.
My XML code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="-50"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
/>
</set>
My java code is:
image1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
image2.setX(image1.getX());
image2.setY(image1.getY());
Animation animation =
AnimationUtils.loadAnimation(MainActivity.this, R.anim.myanim);
image2.startAnimation(animation);
}
});
I am developing an application in which i am having a custom list view. One item of list view contains four text box. The need of app is like when i click on one text box, one image view should be visible, zoom in and then zoom out, and after zoom out the visibility should be gone.
What i tried is :
In adapter in getView method
if(clickPosition == position){
holder.imageViewOne.setVisibility(View.VISIBLE);
holder.imageViewOne.startAnimation(zoominout);
zoominout.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation arg0) {}
#Override
public void onAnimationRepeat(Animation arg0) {}
#Override
public void onAnimationEnd(Animation arg0) {
holder.imageViewOne.setVisibility(View.GONE);
clickedPosition = -1;
}
});
}
My animation XML
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3"
android:toYScale="3" >
</scale>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5"
android:startOffset="2000" >
</scale>
</set>
When i run my app the animation is working good.
But the issue is :
1) The visibility gone on image view is not working.
2) I am having list like below image :
When i click on list item one, first textview, Animation is working, But when i click on list view 2 first textview animation is working on both List item 1 and List item 2.
What should i do for this? Am i missing something? Please guide me with your valuable suggestions.
You need to maintain an array of status of each images whether it is visible or not. You have to apply checks for visibility on the basis of that array of status on each of the ImageView in your getView() method. Now everytime when your animation ends for an ImageView, you have to update the corresponding status of that image in your array of status and just call notifyDataSetChanged().
I'd like to apply 2 alternate rotation animations to a View. Each rotation should start after the click on the same View.
The result I'm looking for is:
the user clicks on the View and it rotates from 0° to 135°
the user clicks again on the View and it rotates from 135° to 0° (to the initial state)
The problem is that, when the user performs the second click, the Button resets to the initial aspect before starting the animation correctly.
I'm targeting Android APIs<11 so I'm using the startAnimation() method. The animations are applied to a Button view defined as follows:
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
The animations are the following
rotate_cw.xml (0° to 135° rotation):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<rotate
android:duration="300"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="135" />
</set>
rotate_ccw.xml (135° to 0° rotation):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="300"
android:fromDegrees="135"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0"/>
</set>
The animations are then applied in this way, where flag is a boolean global variable:
Button b = (Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (flag) {
Animation a = AnimationUtils.loadAnimation(this, R.anim.rotate_cw);
b.startAnimation(a);
} else {
Animation a = AnimationUtils.loadAnimation(this, R.anim.rotate_ccw);
b.startAnimation(a);
}
flag = !flag;
}
});
Am I missing anything?
Thanks in advance for your help.
I'd like to add a press/touch effect to my widget. I'm trying with something like:
remoteView.setInt(R.id.layout_appwidget_imageButtonPrevious,
"setAlpha", 50);
remoteView.setInt(R.id.layout_appwidget_imageButtonPrevious,
"setAlpha", 255);
When the RemoteView is clicked. The problem is that there is a certain delay for the effect to take place and so only the second one is actually shown in the widget (so there is no visible touch effect). If I drop the second instruction I have a touch effect but it is permanent, which of course is something I don't want to have.
How can I solve this issue?
Thank you very much
With an animation:
iv = (ImageView) findViewById(R.id.imageView);
iv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Animation animFadein = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
iv.startAnimation(animFadein);
});
in res/anim/fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="100"
android:fromAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
What I am attempting to do is scale an ImageView from it's normal size, to 20% larger and then back. This should be looped. I have done this with the following code but it doesn't quite work right. More below.
anim/scale.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.2"
android:toYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false" />
<scale
android:startOffset="1000"
android:duration="1000"
android:fromXScale="1.2"
android:fromYScale="1.2"
android:toXScale="1.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false" />
</set>
Then in my code I do
private void scaleAnimation() {
final Animation scaler = AnimationUtils.loadAnimation(this, R.anim.scale);
scaler.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
animation.reset();
animation.startNow();
}
});
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
scale.startAnimation(scaler);
}
}, 2000);
}
I have the handler there so I could see what was happening at the start.
The problem is kind of difficult to explain.. My image appears to get scaled as soon as the animation starts AND THEN it performs the animation. So the image appears, as it should, for 2 seconds. Just as the animation starts it suddenly gets bigger by what appears to be 25% - 50% and then the animation performs properly. Once the animation is over, the image resizes to it's original size really quickly and then gets scaled up again and then the animation starts over.
I've tried with a couple of different images without difference. It is my understanding that fromXScale=1.0 starts the animation with no scaling, i.e. the image as is. Hopefully someone can shed light on what I've done wrong or where I've misunderstood the concepts.
Cheers
If what you're trying to accomplish is an view that scales from 1.0 to 1.2 back to 1.0 constantly, you could make your animation simpler.
You would do the following:
Only define one scale animation (from 1.0 to 1.2)
Set the repeat count to INFINITE
Set the repeat mode to REVERSE
For more info, you can check out the document on the Animation class
In my case, I need to animate my view one time (1.0f -> 0.6f -> 1.0f)
The solution of cheezy works for me changing repeatCount = 1 instead of infinite.
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:duration="600"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatMode="reverse"
android:repeatCount="1"
android:toXScale="0.6"
android:toYScale="0.6" />
</set>