Dropdown menu in android - android

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

Related

Android new fragment appears below old one during fragment animation

I'm using animation between my fragment :
slide in from left :
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="600"
android:propertyName="x"
android:valueFrom="2000"
android:valueTo="0"
android:valueType="floatType"
android:fillAfter="true"/>
</set>
slide in from right :
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="600"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="-400"
android:valueType="floatType"/>
</set>
This animation move the previous fragment to left and the new one come from the right. I'm using it with a fragment transaction.
transaction.setCustomAnimations(R.animator.slide_in_from_left,R.animator.slide_in_from_right);
I got a trouble when the new fragment come he slide below the older one, for fix it I put an elevation on my new fragment but I would like a solution for API below 21.
Is it possible to force the new fragment to be above the older fragment
If I understand correctly, you are using the android:elevation attribute on your new fragment (if not, feel free to write about your method) - altough it only works on Lollipop and above, as you also mentioned. However, based on the linked topic below there are several ways to achieve elevation effect on pre-Lollipop devices.
"android:elevation=" doesn't work on devices pre-Lollipop with compile API21
EDIT AFTER FIRST COMMENT: Okay, sorry for misunderstanding your question... :)
As I searched a little bit in the topic, there were some interesting examples with a new fragment overlapping an older one, they are listed below. The first 2 examples need some special layout design and extensions of existing view classes, but maybe one of them is what you're looking for.
In my opinion the prettiest solution would be based on this example: http://swarmnyc.com/whiteboard/android-fragment-animations (the layout does not contain a FrameLayout to replace fragments, it contains the fragment(s) by the <fragment> tag; in the code you can use simple transition animations; you can find the source code at the end of the topic)
Here's another one: http://trickyandroid.com/fragments-translate-animation/ (you can see an extension of the native RelativeLayout view class with built-in functions to achieve animation; source code also provided at the end of the topic)
Moreover (without source code) I could suggest you 2 more ways:
The animation you search for could be perfectly achieved by using
activities for displaying the UI and the
overridePendingTransition() method inside the activity after startActivity(intent). However if
you really would like to use fragments, maybe you will skip this.
The last (and I think the simpliest) solution could be to overlap the old fragment by adding a new
fragment instead of replacing it. However I think this is the worst
solution because of possible memory usage problems (older
fragments won't be removed, just simply faded by newer fragments).
I hope I could help... :)
If fragment appears below another one is because the fragment container is not the good container type
You need to put fragment inside FrameLayout or RelativeLayout, if you want to test you can paste your fragment layout code at the bottom of the fragment container for have a preview

Android animated transition

How to make circular animated transition from top left to right bottom not as traditional way, I tried
<translate
android:duration ="1200"
android:fromYDelta="-1000"
android:toYDelta="0"
/>
You could use Android transition API. If you're supporting Lollipop+ (ArcMotion was added in Lollipop while transition API is available from KitKat) you might use native transitions, otherwise you might want to use Transitions-Everywhere library. I think this does what you want to do: https://github.com/andkulikov/Transitions-Everywhere/blob/master/sample/src/main/java/com/andkulikov/transitionseverywhere/PathMotionSample.java

How I can implement a button on Android like this (3D-ish)?

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).

Making game like menu in Android

I'm trying to cope with some problem in finding good idea. I would like to make interesting menu like in games on Android (eg. ANngry Birds or here: http://www.youtube.com/watch?v=Q3g6SdTODY4) In this panda game I supose that first menu are simply 3 color buttons, but what about this sliding menu later with stages description - this same as in angry birds? Telling the truth I have got no idea what object it can be?
I will be glad if someone can tell me that. Or the best to give some tutorials about it. I cant google any.
Well, it seems that this sliding stage description is implemented with some simple layout placed to HorizontalScrollView and some animation applied to the buttons.
It can be your custom view provided with your translation animations and handling its visibility on the click of the default menu button (via onKeyDown()) on Android.
There are similar questions:
Custom options menu in Android
Android: customize application's menu (e.g background color)

Duplicating title bar shadow

How would I go about implementing a shadow like the one you see under the title bar? I know this can be done (see for example the app "Andlytics", where this effect shows on the bottom as well).
My best guess is that it's a banner image used as the background for the layout. But maybe there is a better way?
I looked through the images in the SDK's data/res folder and I found what is probably being used: title_bar_shadow.9.png . Errr, can't attach it here, but you should be able to find it in your android-sdk-location/platforms/android-N/data/res/drawable-hdpi/ folder.
I'm guessing it is probably achieved by using a 9-patch with a gradient on the top edge and corners as the layout background. I don't know of any better way, but this should be pretty simple to implement.
Take a look at this question: Custom ImageView with drop shadow
Or we could use a gradient - and Android seems to be going that way.
In later versions of the platform SDK code, the title bar image is replaced by action_bar_divider.xml.
The divide is nothing but:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#ffe1e2e4"
android:endColor="#ff95979a"
android:angle="270" />
</shape>
You can use it in an image view just below your title bar.

Categories

Resources