android - frame animation in value/arrays.xml - android

i have simple anim
simple_anim.xml
<animation-list xmlns:android=”http://schemas.android.com/apk/res/android” id=”selected” android:oneshot=”false”>
<item android:drawable=”#drawable/frame1″ android:duration=”50″ />
<item android:drawable=”#drawable/frame2″ android:duration=”50″ />
</animation-list>
it is possible to create frame animation in value/arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<array name="entries">
<item>#drawable/simple_anim</item>
<item>#drawable/image2</item>
<item>#drawable/image3</item>
<item>#drawable/image4</item>
<item>#drawable/image5</item>
</array>
</resources>

Technically yes. But not in the same way you would use the first one. You could start a thread that on each run displays the next image resource in your array.

Related

How to get drawable resource from boolean resource

Is there a way to get a drawable resource from a boolean resource?
For example:
bools.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="use_version_1_drawables">true</bool>
</resources>
my_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/my_drawable_version_1"/>
<item android:drawable="#drawable/my_drawable_version_2"/>
</selector>
Is there a specific state I should be using because from what I understand they are all related to specific events (checking, focusing, etc). Perhaps I shouldn't be using a selector. I simply want to have one resource I can call upon that's actually linking to two others but will select one based on my bool.
You are close. You can think of a selector as an if/else statement. What you're missing now is your actual state. Here is an example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimaryDark" android:state_checked="true" />
<item android:color="#color/gray" android:state_checked="false" />
</selector>
If you're using it with something like a Checkbox, then just set this selector as a drawable resource for the checkbox, and state_checked will be updated automatically.
EDIT: Problem was slightly more complex, and solved in the comments.

Animation_list must be declared error

Having read Drawable Animation , Animation Resource, and other stackoverflow questions, i thought that putting this in the drawable file was the proper way of creating an animation_list.
<?xml version="1.0" encoding="utf-8"?>
<animation_list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="#drawable/james_walking_1" android:duration="200"/>
<item android:drawable="#drawable/james_walking_2" android:duration="200"/>
<item android:drawable="#drawable/james_walking_3" android:duration="200"/>
<item android:drawable="#drawable/james_walking_4" android:duration="200"/>
</animation_list>
However , animation_list is red and "must be declared". I dont know what is wrong. Thanks in advance
Use animation-list, not animation_list.

Where do I save selector color on android

Here is my selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#color/black"/>
<item android:color="#color/white"/>
</selector>
apparently I cannot save it in the /drawable folder as my android won't compile. Then if I create a /color folder in res I get a red mark from eclipse. So where do I save my selector so I can use it as the background color of a TextView (or really any other view).
I have a colors.xml file in values, but how would I add a selector to it?
THE ACTUAL SOLUTION
I am posting this edit in case someone else needs help. I hope you this saves you some time.
For the correct answer, I did following
In strings.xml
<drawable name="black_drawable">#color/black</drawable>
<drawable name="white_drawable">#color/white</drawable>
In colors.xml
<color name="black">#000000</color>
<color name="white">#ffffff</color>
Then in the selector, I did
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/black_drawable" android:state_pressed="true"/>
<item android:drawable="#drawable/white_drawable"/>
</selector>
The selector is saved in /drawable as selector_black_white.xml
Here's a solution I found.
You just need to create a "color" folder in your res and save the file in the newly created folder.
After completing this step you will be able to get the color selector file in your attribute of respective xml file.
I'm attaching screenshots for better understanding.
Step 1
Step 2
Last edit i messed up pretty in my previous edit sorry my bad this one is working now
res/drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#color/whiteColor"/>
<item android:drawable="#color/backColor"/>
</selector>
then on your res/value/string or create new values color
<color name="whiteColor">#000000</color>
<color name="backColor">#ffffff</color>
I think your problem is not the location - it should be in the /res/color folder. The problem is in how you specify the color:
<item android:color="#color/ffffff"/>
should be
<item android:color="#ffffff"/>

Can I move the android:duration of an animation-list item to attrs.xml?

Is it possible to have an animation like this:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="#drawable/pr_l_b01"
android:duration="#dont-know-what/animation_frame_duration"/>
<item
android:drawable="#drawable/pr_l_b02"
android:duration="#dont-know-what/animation_frame_duration"/>
<item
android:drawable="#drawable/pr_l_b03"
android:duration="#dont-know-what/animation_frame_duration"/>
</animation-list>
and in attrs.xml:
<dont-know-what name="animation_frame_duration"/></dont-know-what>
?
Take a look at the duration attribute in android developers.
This may also be a reference to a resource (in the form "#[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
Insert your duration value in values.xml like this:
<resources>
<integer name="duration">700</integer>
</resources>
And use it like this:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="#drawable/pr_l_b01"
android:duration="#integer/duration"/>
</animation-list>

Displaying activity with custom animation

I have a widget which starts an activity when it is clicked. I'd like to have some kind of fancy animation to display this activity, rather than the standard scroll-from-right of Android. I'm having problems setting it, though. This is what I have:
slide_top_to_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_interpolator">
<translate android:fromYDelta="-100%" android:toXDelta="0" android:duration="100" />
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="50" />
</set>
...which is referenced in anim.xml
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="50%"
android:animation="#anim/slide_top_to_bottom" />
But then where do I reference it from? I've tried both the base element of the activity I want to slide in, and the activitiy's entry in the manifest, both times with
android:layoutAnimation="#+anim/anim"
I might be doing this all wrong. Any help is much appreciated!
You can create a custom Theme with a reference to your own animation and apply it to your Activity in your manifest file.
I was successful in applying a custom animation for a floating window using the following style definition. You might be able to do something similar if you set the parent of your style to be "#android:style/Animation.Activity"
Look at the following files for further details on what you can override.
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml
Here's my a portion of my styles.xml and manifest.xml
styles.xml
<style name="MyTheme" parent="#android:style/Theme.Panel">
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">#style/MyAnimation.Window</item>
</style>
<!-- Animations -->
<style name="MyAnimation" />
<!-- Animations for a non-full-screen window or activity. -->
<style name="MyAnimation.Window" parent="#android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">#anim/grow_from_middle</item>
<item name="android:windowExitAnimation">#anim/shrink_to_middle</item>
</style>
Manifest.xml
<activity
android:name="com.me.activity.MyActivity"
android:label="#string/display_name"
android:theme="#style/MyTheme">
</activity>
startActivity(intent);
overridePendingTransition(R.anim.slide_top_to_bottom, R.anim.hold);
Check this link: overridePendingTransition method
Edit:
To Achieve the Animation for the Views. You have use the startAnimation Method like below
view.startAnimation(AnimationUtils.loadAnimation(
WidgetActivity.this,R.anim.slide_top_to_bottom));
Check this link:
It doesn't matter that your starting from a widget, wrote a tutorial so that you can animate your activity's in and out. This animation is set within the activity that your bringing into focus so you can do it with pendingIntent as well.
Enjoy:
http://blog.blundellapps.co.uk/animate-an-activity/

Categories

Resources