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
Related
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
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).
Is is possible to use FragmentTransaction and the remove() method to get rid of fragments that are defined in the layout.xml (using the fragment tag) ?
I did not get this to work using the support libraries v4. The fragment stays in place after you commit the FragmentTransaction, after calling remove(). Can anyone tell me if this is by design, a bug or a feature?
It is possible to replace a fragment that is defined in the lyaout.xml, so I find it a bit strange that it should not be possible to remove it?
The native APIs available starting in Honeycomb work the same as those in the support libarary, so you cannot remove an instance of a Fragment which has been declared in your layout XML file.
With FragmentTransactions you manipulate ViewGroups such as LinearLayouts that act as containers to hold the layout of other Fragments. However, when you declare a Fragment in your layout, it doesn't have a container in the same sense because it is permanently part of the View hierarchy, so you can't remove it. That is by design, to support things like navigation Fragments that you'd never remove anyways. :)
One thing that's interesting, and I found it out totally by accident, is that you can add new Fragments into a Fragment that was declared with the tag in your layout; and it acts as a container for other Fragments
Like #david-c-sainte-claire and #martÃn-marconcini said, you can't use remove() method and FragmentTransaction to remove the fragment that was defined in the XML. That doesn't mean you are out of luck. You can always use setVisibility() method.
findViewById(R.id.fragment_main).setVisibility(View.GONE);
I did not this to work using the support libraries v4. The fragment
stays in place after you commit the FragmentTransaction, after calling
remove(). Can anyone tell me if this is by design, a bug or a feature?
This is by design (or a lack of a feature, not definitely a feature if you ask me :P). So as long as you are using the support libraries, you can't achieve this.
As an exercise, I am trying to rewrite the following google tutorial with Fragment class. The original tutorial implements tabs by using the old TabActivity class and TabHost/TabWidget annotation.
Tab Layout Google Tutorial
I have converted all Activity class with Fragment. I couldn't make my new code to work. I think I am stuck.I could not find any 'complete' Tab sample code using Fragment class.
Here are my questions
1. Should I define in the res/layout/main.xml or calling Actionbar.addTab(...) in my entry class, or both?
2. What would be complete res/layout/main.xml looks like? What would be the root element (i.e. LinearLayout, FrameLayout...etc)?
3. Any additional info would be greatly appreciated.
Check out this example from the compatibility library demos: FragmentTabs.java
and the corresponding layout: fragment_tabs.xml
Really, though, I wouldn't start with Tabs if you're trying out Fragments for the first time. Tabs in Android are a little bit of a mess. The above example (from Google itself) uses a hack just to get things working. Tabs just add a layer of unnecessary confusion when you're just learning.
Here's a more straightforward starting-out Fragments example/tutorial: http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html
(Just make sure to replace things like getFragmentManager() with getSupportFragmentManager() if you're using the compatibility library.)
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