I'm working on a custom indeterminate spinner, I browsed through the SDK for some pointers and found the indeterminate spinner xml file made by Google:
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/spinner_black_16"
android:pivotX="50%"
android:pivotY="50%"
android:framesCount="12"
android:frameDuration="100" />
When I use this as a drawable in my own project I get errors about android:framesCount and android:framesDuration. After looking on Google for a while I found this link to an issue report.
My questions is: Is there any workaround so i can still use android:framesCount and android:framesDuration? Or is there any other way I can make my custom spinner rotate smooth?
Have you looked at the answer to this question? How to make a smooth image rotation in Android It appears that you are having the same issue. He doesn't use the following:
android:framesCount="12"
android:frameDuration="100"
Since it appears to be internal I would recommend going about it the way he did.
Hope this helps.
I replaced animated-rotate with rotate
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/ic_loading"
android:pivotX="50%"
android:pivotY="50%" />
Related
What is the easiest way to create a Circle in Android Studio (1.2)?
I understand I can do it through using canvas code or writing XML code somewhere, but this seems really complex. None of the guides on the internet seem to provide a simple way. Simple would be drag-and-drop from the menu in Design view of Android Studio, jus tlike widgets.
Been searching for all of today, you can imagine how frustrating this incredibly simple thing is.
The best way to create a circle in Android is using XML drawable.
They don't have an exact circle shape, but oval shape will do the same job
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<solid android:color="#000000"/>
</shape>
I have requirement of implementing Genie Effect animation shown below.
Reference:
https://github.com/Ciechan/BCGenieEffect
I could not understand where to start. Can anyone suggest me some ideas?
I tried some code with basic animation like translation and scaling but not succeed.
I have implemented this code with Game Library AndEngine
Kindly find the attached code below that will help u to move further..
you can use this code as fragment to ur android code OR make instance
of this code and again extend from activity for reusing this code.
This zip file contain 2 project :
Code implementation for above effect and
AndEngine library which u need to add to my project .
Click here to Download My Code
I tried to make animation like Genie Effect. But its not as perfect as your image show, but It will help you during your research.
Example Video of demo.
Create anim folder in res. copy falling.xml
falling.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator" >
<translate
android:duration="750"
android:fromXDelta="0%p"
android:fromYDelta="10%p"
android:toXDelta="0%"
android:toYDelta="50%" />
<scale
android:duration="750"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="100%"
android:toXScale="0"
android:toYScale="0" />
</set>
Use following java code to apply animaiton on button click.
final Animation animationFalling = AnimationUtils
.loadAnimation(GenieEffectActivity.this, R.anim.falling);
imgview.startAnimation(animationFalling);
Hope it helps you.
I have a browser solution.
Check out https://github.com/kamilkp/geniejs
and http://kamilkp.github.io/ for demo.
It works in every browser including mobile (not always smoothly on firefox though). It supports Genie Effect transitions in every direction (top, bottom, left, right). It works even if the target html element is a child of some container that has overflow auto or hidden. It is library agnostic itself, but i also wrote a convenience jQuery plugin. And if you also include the html2canvas library in your project, the plugin lets you animate HTML elements with genie effect (expanding example here: http://kamilkp.co.nf/genie/canvas/)
The only requirement for the browser is that it needs to support CSS transitions. It's a pure javascript + CSS solution.
PS. You can use Phonegap to create an Android app from a web application.
I'm defining a ScaleDrawable in XML according to the Android developers site example:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/sign_ui_text_line"
android:scaleGravity="center_vertical|center_horizontal"
android:scaleHeight="80%"
android:scaleWidth="80%" />
I define this as the background of an EditText
for some reason the drawable isn't displayed (but the EditText view changes it's size according to the definitions).
why doesn't it display ?
how can I scale a drawable to be used as a background ?
ScaleDrawables seem to require some workarounds in order to work properly, from the sounds of things.
See Zeh's answer to a similar question.
I have followed the tutorial at:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Animation1.html
The code is fine until I get to:
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
It would appear that R.anim does not exist, eclipse suggests creating a field in in type R or creating a constant in type R. Correct me if I'm wrong but I don't believe either are the solution.
I am running Google APIs, platform 2.2, API 8 - I have tried higher levels but it didn't make a difference. All that I am trying to accomplish is a button shake on click...
Any feedback is appreciated,
Thanks
You need to create the shake animation xml file. It will reside in
/res/anim/shake.xml
and it would look like this:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="10" android:duration="1000"
android:interpolator="#anim/cycle_7" />
You then also need the interpolator (cycle_7.xml):
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="7" />
These files can both be found in
/path/to/android_sdk/samples/android-15/ApiDemos/res/anim
The following code is not working for me.
finish();
overridePendingTransition(R.anim.slide_up,R.anim.slide_up);
startActivity(intent);
overridePendingTransition(R.anim.slide_up,R.anim.slide_up);
and the XML for animation is
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%p" android:toXDelta="-50"
android:duration="#android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
I searched the web, saw all the threads from Stack Overflow, but not able to fix this.
I made it work out in the following way.
I have removed the
overridePendingTransition(R.anim.slide_up,R.anim.slide_up);
from the above code and placed it in onPause(), and it worked like a charm.
Sometimes animations are disabled on the phone. To check go to settings > display > animation > allow "all animations". This will allow overridePendingTransition to work properly if it was disabled.
If you activate usb debugging mode, it can disable the transitions effects.
Enter Developer options (where you activated debugging mode), find the user's interface section, check if the animation's transition scale have the animations disabled. If so, set it to .5x. Done!
try startActivity before finish()