I'm trying to make a custom navigation drawer in android.
It should compromise of a spinner view for selecting city from the list, then city temperature and then name, email and contact no.
I'm able to make city option and edit text list for name, email etc. Now I can't insert temp details in it.
need help
Closing animation of your slider
public static void playcloseanimationofleftdrawer() {
TranslateAnimation translateAnimation = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
AnimationSet animation = new AnimationSet(false);
animation.addAnimation(translateAnimation);
animation.addAnimation(alphaAnimation);
animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// Do nothing
}
#Override
public void onAnimationRepeat(Animation animation) {
// Do nothing
}
#Override
public void onAnimationEnd(Animation animation) {
}
});
animation.setDuration(500);
leftdrawer.startAnimation(animation);
}
Opening animation of your slider
public static void playopenanimationleftdrawer() {
TranslateAnimation translateAnimation = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, -4.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
AnimationSet animation = new AnimationSet(false);
animation.addAnimation(translateAnimation);
animation.addAnimation(alphaAnimation);
animation.setDuration(1000);
animation.setFillAfter(true);
leftdrawer.startAnimation(animation);
}
Just think how you can achieve that!Anyway giving you how to do it.First make relative layout inside your layout,call that relative layout lets say left drawer.After which give that new created layout a color,basically you might want to give white color,ok next step is to give the height of relative layout
match_parent or fill_parent
and the width of your layout should be fixed size...or if you want your drawer to be from start of screen to end of screen you can still use above written code.So after all this all you have to do is to put a button above your created layout(most useful button is ToggleButton as it have 2 states to be pressed(on/off)) and that button will make your created layout to go either VISIBLE or INVISIBLE,so here you have custom sliding drawer where you can put any widget you like and put some translate animation onto it to make it fell real drawer.Good Luck
Related
I wonder how to animate current Activity, not transition between activities. For example, I want to shift the activity slightly to the left and then move it back, so that it looks like a little shake effect. Any ideas? Thanks
Finally I have found a solution:
Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -0.05f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
animation.setDuration(100);
animation.setInterpolator(new AccelerateInterpolator());
animation.setRepeatCount(1);
animation.setRepeatMode(Animation.REVERSE);
View viewActivity = findViewById(android.R.id.content);
if (viewActivity != null)
viewActivity.startAnimation(animation);
you need to create animation instance like below
Animation startAnimation = AnimationUtils.loadAnimation(context, R.anim.shaking_animation);
then u need to start that animation with your parent layout
parent_layout.startAnimation(startAnimation);
you can get shake animation here shaking / wobble view animation in android
finally you can clear animation like below
parent_layout.clearAnimation();
The basic idea is to get access to the root layout of the activity and then do some animations on it, e.g. if you use DataBindung it is just like this (but not the best idea for the kind of animation you want):
binding.getRoot().animate().rotation(-5).setDuration(500).setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
binding.getRoot().animate().rotation(5).setDuration(1000).setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
binding.getRoot().animate().rotation(0).setDuration(500);
}
});
}
});
I have a custom slide-out menu implementation (not using any library) in which I slide my layout towards right and show menus on the left (like facebook, google+ app does). After the menu is shown I fade the right layout by giving some alpha value as shown in the code below:
<FrameLayout
android:id="#+id/fl_mask"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:alpha="0.7"
android:background="#color/black">
</FrameLayout>
But this all happens when my menu is shown. What I want is, as the layout slides towards right, I want to darken it. Farther the layout from left edge, darker the layout. Moreover, I use following code for layout animation which slides my layout towards right.
public Animation SlidingAnimation(int animateDuration, boolean slideLeftToright, final boolean executeOnAnimEndCode) {
Animation animation = null;
AnimationSet set = new AnimationSet(true);
if (slideLeftToright) {
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
} else {
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
}
animation.setDuration(animateDuration);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
if (executeOnAnimEndCode) {
... // Some piece of code
}
}
});
set.addAnimation(animation);
return animation;
}
How can I fade/darken my layout as it slides towards right?
In your
public void onAnimationEnd(Animation animation)
{
if (executeOnAnimEndCode)
{
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f);
alphaAnimation.setFillAfter(true);
someLayout.startAnimation(alphaAnimation);
}
}
});
or you can also declare animation as xml and then use it....
I am trying to perform 2 text animations in a row with my TextView under Android
first:
TextView target = (TextView)findViewById(R.id.textanimation);
target.setText(text1);
target.startAnimation(animationSet1);
animationSet1 is a set of alpha and translate animations:
Animation alpha = new AlphaAnimation(0.0f, 1.0f);
Animation a = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0);
alpha.setDuration( 1000 );
a.setDuration( 1000 );
When onAnimationEnd happens in animationSet1 I immediately start another animation
TextView target = (TextView)findViewById(R.id.textanimation);
target.setText(text2);
target.startAnimation(animationSet1);
However in the 2nd animation I can see on a split of second a fully opaque text, however it should start with 0 alpha. How to avoid this situation? Will appresiate any answer.
P.S. Even if I have 2 separate textviews with the prepared text in both - same bug is seen.
If I put some delay between the animations both of them become smooth.
Sergey
I'm not sure how you are triggering the start of the 2nd animation following the termination of the 1st animation. I'm guessing you're checking to see if the animation on a view is null. This isn't the best or correct way to do it. Instead you should you an AnimationListener
Animation animation1 = new Animation();//Replace with your animation
animation1.setDuration(DURATION_1);
animation1.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation arg0) {}
public void onAnimationRepeat(Animation arg0) {}
public void onAnimationEnd(Animation arg0) {
Animation animation2 = new Animation();
animation2.setDuration(DURATION_2);
view2.startAnimation(animation2);
}
});
view1.startAnimation(animation1);
suppose i have three text as heading.Any how you can take textview or anything.one text on left,one in center and one in right side.so i want an animation when i will slide the screen left then left text will be gone,center text will come to left and right text will come to center.Same thing for right slide.Can anyone suggest how can i achieve this type of animation.Plz help.
You can try to create an animation variable :
private Animation leftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
then
set this action to your frame:
public void onLeftArrowClick(View v) {
frame.setAnimation(moveComingSoonToBottomAnim); // your Frame variable
animVariable.startNow();// your anime variable
frame.setVisibility(View.VISIBLE);
rightFrame.setVisibility(View.GONE); // hide your right text view
}
I applyed a TranslateAnimation to an EditText with the FillAfter=true in order to keep its position at the end of the animation.
The animation works properly but the problem is that I can't enter to the edittext anymore.
I think it's due to the fact that the animation affects only the rendering without modifying the actual view coordinates.
Is there any possibility to maintain the final coordinates with the edittext normally working?
Thanks,
Daniele
Unfotunately the animation only renders the raw pixels of the animated element, but not its "android-intern" position. The best solution (that i am able to come up with) is to use an AnimationListener and set the position of the animated element correctly after the animation has finished. Here is my code to slideDown a searchWrapper:
public void toggleSearchWrapper() {
AnimationSet set = new AnimationSet(true);
// slideDown Animation
Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f
);
animation.setDuration(300);
animation.setFillEnabled(false);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(final Animation anim) {
};
#Override
public void onAnimationRepeat(final Animation anim) {
};
#Override
public void onAnimationEnd(final Animation anim) {
// clear animation to prevent flicker
searchWrapper.clearAnimation();
// set new "real" position of wrapper
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.BELOW, R.id.branchFinderIncludeHeader);
searchWrapper.setLayoutParams(lp);
}
});
set.addAnimation(animation);
// set and start animation
searchWrapper.startAnimation(animation);
}