I guess this is kind of an odd question but I have tried setting onClicklistener on an ImageView and it has worked. But the problem is that the user cannot sense the click. I mean if some of u have worked on other mobile environs(like Apple iPhone) then when we click on an Image in other environs then it gives an effect on the image so that the user can understand that the image has been clicked.
I have tried setting alpha using setalpha method but it doesn't work. Though the same thing is working fine on onFocusListener implementation. Can some1 suggest a different way to modify the image on click...
I am new to android so haven't learnt the nuances of simple animation also... if there is any simple animation I can use for the same then please let me know.
Thanks!
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha = "1.0"
android:toAlpha = "0.5"
android:duration = "300">
</alpha>
<scale
android:fromXScale = "1"
android:toXScale = "0.9"
android:fromYScale = "1"
android:toYScale = "0.9"
android:pivotX="50%"
android:pivotY="50%"
android:duration = "50">
</scale>
</set>
I don't know if this is the correct method but defining an animation as mentioned did the trick. Now we just have to give
public void onClick(View v) {
v.startAnimation(AnimationUtils.loadAnimation(Context, R.anim.image_click));
//Your other coding if present
}
in the OnClick method and the change will be visible...
You'll want to use a drawable that contains different images for the different states you want to support. Here's an example:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/img_pressed" />
<item android:state_focused="true" android:drawable="#drawable/img_focused" />
<item android:drawable="#drawable/img_at_rest" />
</selector>
Name this file img.xml or something and put it in your drawable directory, then set your ImageView's image to img.xml. #drawable/img_at_rest is the original image you're trying to use, while #drawable/img_pressed and #drawable/img_focused are the images to use for their respective states. You can also use solid colors instead of images if it's appropriate for your use case.
anim/anim_item.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1."
android:duration="1000">
</alpha>
</set>
And add:
myView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.anim_item));
Not sure if it works, but have you tried setSelected()
http://developer.android.com/reference/android/widget/ImageView.html#setSelected(boolean)
Related
How to have this blink effect on my notification icon during a download file, like that:
MY ANSWER
Just use this native drawable android.R.drawable.stat_sys_download
mBuilder.setContentTitle(title)
.setContentText(filename)
.setSmallIcon(android.R.drawable.stat_sys_download);
Try using an animation drawable.
For example:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/frame1On" android:duration="1000" />
<item android:drawable="#drawable/frame2Off" android:duration="1000" />
</animation-list>
Where frame1On on is the image highlighted, and frame2Off is the image greyed out. Add more frames if necessary.
I'm new to Android application programming, and using search i've so far solved all of my problems (stackoverflow being one of the best search hits !)
Now i have a problem i don't know how to solve :
When separate animations are required, i could do it in code, but using XML files in anim folder would be much better for me.
Is it possible to play an animation of a single <set> inside XML file ?
I mean is it possible to "compress" animations from mulitple XML files into one file and still use them individually ?
Example for normal animation of TextView widget :
TexView exampleTextView = (TextView) findViewById (R.id.example_textview);
Animation animatorSequence = AnimationUtils.loadAnimation (this, R.anim.example_animation);
exampleTextView.startAnimation (animatorSequence);
XML code with two example blocks that i would like to use separately
<?xml version="1.0" encoding="utf-8"?>
<!--first independant animation segment -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:duration="1400" />
</set>
<!--second independant animation segment -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="1400" />
</set>
You can't.
But you can divide them to multiple files, load the in run time and add them all to a single AnimationSet (You can also define the empty set itself in a XML file so you won't have to configure it programmatically).
We are building an Android app where in the place of splash screen while waiting, i want to add an animation just like Boot animation of Moto G. Not exactly the same, but globe with some other elements will be used.
So my question is how to do it something like that?
Any input is much appreciated.
Thanks,
as for android .. you have to make animation manually ..
for this make xml file with animatiom-list under res/drawable .. then add items and give duration ..
EXAMPLE:::::
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="#drawable/image1"
android:duration="300"
/>
<item
android:drawable="#drawable/image2"
android:duration="300"
/>
<item
android:drawable="#drawable/image3"
android:duration="300"
/>
<item
android:drawable="#drawable/image4"
android:duration="300"
/>
android:oneshot="false" is to repeat animation again and again .. if you dont want to repeat then make it true
after you make animation .. add it in a imageview ..
I'm trying to develop a splash screen with a large image scrolling (Animating) from top to bottom.
I dont think using ScrollView would be good since I dont want the user to scroll the image.
This is what I would like to achieve:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromYDelta="-100%p"
android:toYDelta="100%p"
>
</translate>
</set>
create this animation as slidedown.xml in an anim folder in the project and use the code below in the java file that has the view.You may change the values of "android:fromYdelta" according to your need.
myImageView.startAnimation(slidedown);
For example if your imageview is 250 px use :
ObjectAnimator.ofFloat(myImageView, "translationY", 250);
And in xml set on your imageview :
android:translationY="-250"
I has a nice PopupWindow which I want to appear with an animation. I do it like this:
popup.setAnimationStyle(R.anim.appear);
popup.showAtLocation(popupMenuLayout, gravity, offsetX, offsetY);
I then set up a listener for changing the animation:
popup.setOnDismissListener(new PopupWindow.OnDismissListener(){
#Override
public void onDismiss(){
popup.setAnimationStyle(R.anim.disappear);
}
});
But, hey, it won't work. Neither for res/anim/appear:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%"
android:toYDelta="0"
android:duration="1000"
/>
Nor for res/anim/disappear:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0"
android:toYDelta="100%"
android:duration="1000"
/>
Any clues?
Actually, PopupWindow.setAnimationStyle expects a style with 2 entries. You'll need to have two xmls, each containing a <set>, one for showing and the other for hiding the window. When this is done, put the following piece into values/styles.xml:
<style name="AnimationPopup">
<item name="android:windowEnterAnimation">#anim/popup_show</item>
<item name="android:windowExitAnimation">#anim/popup_hide</item>
</style>
and set your animation style to R.style.AnimationPopup. That'll do.
I've got this information from https://github.com/lorensiuswlt/NewQuickAction3D the documentation didn't seem to mention it.
Update:
An update to Android SDK in 2012 have changed XML syntax. The original #android:windowEnterAnimation now became android:windowEnterAnimation. So this answer is updated accordingly.