I want to implement a button like the one in the "Big Web Quiz App" (Link to Play Store).
For me, it doesn't seems to use some sort of OpenGL, i can't found any references on the dissasembled code. Maybe is an image?
Thanks in advance
UPDATE: I've uploaded a video, to state clearly that there is a transition, it's not a pressed-unpressed button. LINK
You can achieve this by using Frame Animations, its like a short video build from few images.
animation-list is one option to go, read more about it here:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item
android:duration="500"
android:drawable="#drawable/ic_heart_0"/>
<item
android:duration="500"
android:drawable="#drawable/ic_heart_25"/>
<item
android:duration="500"
android:drawable="#drawable/ic_heart_50"/>
<item
android:duration="500"
android:drawable="#drawable/ic_heart_75"/>
<item
android:duration="500"
android:drawable="#drawable/ic_heart_100"/>
</animation-list>
News since 2015 to Aug 2016 lol
Today there are more options to solve this problem, you can use AnimatedVectorDrawable or ObjectAnimator or use android-pathview library that was developed on top of AnimatedVectorDrawable, it makes the life easier. But in any way you will have to put some work to achieve your desired effect.
Off the cuff, this would seem to require a custom widget.
The widget itself would consume the entire space, from the upper-left corner of the foreground through the bottom-right corner of the 3D background. The custom onDraw() of the widget would render the foreground, perhaps in the form of a TextView with a compound drawable on the left. onDraw() would also render the shaded parallelograms that form the 3D effect, to consume the rest of the space between the foreground and the lower-right corner of the widget.
On a click event, you would use the animator framework to change the size of the widget, anchoring it on its bottom-right corner. The animation would change the size to the smallest position, then reverse it back to its original size (assuming that this button is to behave like a Button, instead of some sort of CompoundButton). The onDraw() logic should be able to handle this, rendering the foreground in the correct location and reducing the size of the parallelograms accordingly.
This is all an educated guess, as I have never tried anything like this. It will also get complicated if you want to support RTL by reversing the 3D effect (foreground moves down to the left, instead of down to the right).
Related
Android has a nice reveal animation (called "CircularReveal") that has a circle shape (link here and here) .
I was wondering: is it possible to do it in other shapes too?
For example, reveal a view from top to bottom, in a rectangle shape, as such:
XXX XXX XXX
... => XXX => XXX
... ... XXX
A video of how it looks like can be found here.
In the previous way to do it, I've used a customized ObjectAnimator (link here) that changes the layout params (which works, but it's a workaround and it's not quite customizable, and it will probably not work on this case), but I wonder if there's a new way to do it, something easier and more customizable.
Also, is it possible to make this kind of animation work on previous Android versions, and not just Lollipop?
It's just that I've seen "Google Now Launcher"'s search-history appear this way, and I wonder how to make a similar thing.
You could create a New Animator like this http://cogitolearning.co.uk/?p=1451 and define your own rectangular animator. Here is a reference link to the GitHub source code posted by the author.
The Google Now search history animation just looks like a simple translate to me. It looks like the top search bar is in front of the history drop down. By animating the views in front (of your view you want to be revealed) to go down, I think you would get the reveal you are looking for. See: https://stackoverflow.com/a/19766034/2832027
The only solution I've come up with is to put a view as a second layer (on top of the listView) that is identical to the background, which has a scaled down animation.
so it's like that in the layout XML:
<FrameLayout >
<ListView/>
<View/>
</FrameLayout>
This should work, but it's more of a workaround.
Also, it has some disadvantages:
another layer means more overdraw.
might be tricky in case you have a complex background.
it's probably not as nice to use as a real reveal-animation.
Check my project: https://github.com/mageRabbitStudios/coolandroidstuff/tree/master/MyCircularReveal_12_3_19
In there you can create any reveal animations you wish. It will sound complicated but is quite simple. I created custom ImageView where I access the "clipPath" property of its canvas.(The only way I found to change the clip mask of a view, there is simpler solution shown on the third ImageView where I access only clipBounds property of the ImageView and during that it is not neccessary to create custom view) I update the clipPath on every draw which is called only during the animation's execution using AnimatorUpdateListener and using ObjectAnimators and custom Evaluator I manage to create from circle to rectangle reveal animation :)
Convert it to Java if you don't understand Kotlin
I am creating my first Android App that will be making profit, selling it to a company. I am not very advanced yet in Android App Development.
I have two buttons. I have been able to detect when the bottom of a ScrollView has been reached. Once that happens, one of the buttons becomes clickable, Button.setClickable(true);
When the button is not clickable, I would like it dimmed.
Here is an example from another application I wrote of what I mean. It is written in Java, but it is not an Android App.
Many buttons and other components there are disabled until the one with the diamond (turns on scanning) is toggled on. Those disabled components have a dim look to them. I would like to know how to accomplish the same for Android. I have searched Google but not found anything relevant yet.
P.S. If you would like to know more about the software in that picture I created. It is open source and you can check it out here.
https://github.com/BullShark/JSpeak
Similar answer to Anup Cowkur, but I believe it's cleaner and a better practice to define a single drawable with different states.
dimmable_button.xml (put in your res/drawables folder)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item state_enabled="true"
android:drawable="#drawable/clickable_image" />
<item state_enabled="false"
android:drawable="#drawable/dimmed_image" />
</selector>
Then, the layout file where your button is defined:
<button
....
android:background="#drawable/dimmable_button" />
Now, when you do button.setEnabled(bool) the button's background will change automatically to a dimmed one.
Simply make another image with whatever look you want and change the background of the image to it when it is not clickable.
When it is dimmed out:
button.setBackgroundResource(R.drawable.dim_image);
When it becomes clickable again:
button.setBackgroundResource(R.drawable.clickable_image);
Did you tried
myButton.setEnabled(false);?
or
android:clickable can be used via xml
I have a DialogFragment which I show() when the user clicks a button on my App.
I would like to set an animation to make a Z-axix rotation on the DialogFragment when it launches (i.e. a 3d card flip animation).
I have succesfully used the windowAnimationStyle and the following style to do simple animations (using the View Animation framework) when the DialogFragment is shown:
<style name="windowAnimationCardFlip" parent="#android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">#anim/card_flip_left_in</item>
<item name="android:windowExitAnimation">#anim/card_flip_left_out</item>
</style>
The problem is that the View Animation framework is (to the best of my knowledge), quite limited, and the only rotation that I'm able to do (on xml, at least) is a 2D XY rotation (I want a "3D" z axis rotation).
I tried to use the Property Animation framework (specifically an Object Animator, written in XML), but, while I'm able to achieve the effect when loading simple Fragments as described in the official android tutorials, when I try to apply that XML ObjectAnimator to the windowEnterAnimation attribute, nothing happens.
I would like to know, then, what could be happening? Is it possible to use an ObjectAnimator to animate the windowEntry event? If not, are there other solutions?
I wanna make a dropdown-menu like the one in the attached picture in android I searched a lot but I Couldn't find anything?
Could you tell me how to start?
If you are trying to do something where you see a list of items as you type in text into a TextView, you may be looking for an AutoCompleteTextView. An implementation example can be found here.
If you are trying for the more usual drop down menu, you may want to use a Spinner widget. An example of its implementation can be found here.
Let me know if you need any more help.
Android does not generally use a "dropdown-menu" like the one you have in your screenshot. I encourage you to learn the Android UI framework and stick to it.
In Honeycomb (the tablet UI), there is the "nav mode" of the action bar that will look a bit similar, though it is not designed to be a menu.
Your best bet is going to be to make a view with the menu you want.
Then make an animation that will grow the X and Y scale over some amount of time.
Ex:
android:fromXScale="0.1"
android:toXScale="1.0"
android:fromYScale="0.1"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="0%"
android:duration="#android:integer/config_shortAnimTime"
Then all you have to do is apply the application to your view in the appropriate onclicklistener
I have a bar with several ImageViews, each of them is used as a button (by using the OnClickListener). Now what I want to achieve is when a user pressed the image, some kind of a glow effect will appear around the image (much like when you press barButton on the iphone).
Is this possible?
This is possible. The correct way to achieve this is to define a StateList Drawable.
The statelist defines a separate drawable for each state.
For example the following xml defines a drawable that shows the blue_button_pressed drawable if the button is pressed and the blue_button_active drawable in all other cases.
<?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/blue_button_pressed"/>
<item
android:drawable="#drawable/blue_button_active"/>
</selector>
You put this file in the drawable folder like any other image and also reference it in the layout files like any other drawable.
Most Views don't actually animate animatable Drawables though, for some reason. To do this, you have to manually start the animation by calling the start() method on the AnimationDrawable (or Animatable, for that matter).
You can't do this immediately after setting the Drawable to a View though, for some weird reason. Instead, you can try to post the start call to a Handler, so that there is some time between the initial setting of the Drawable and the start of its animation.
Didn't have time to find out why it behaves like this yet, but it is what I ended up having to do.
You could manually generate this glow effect as a background picture and make it appear as a parent view behind the actual images when clicked. But I don't think there is any native function for that.