Prevent dimming when starting activity android - java

When I switch activities in my android app, there is a quick (half a second) dim in the screen, as it renders.
e.g. If I press a button that starts an activity, the screen will quickly dim.
Is there anyway I can stop this???
Many Thanks
Ed

Maybe if you try to turn off animation you will get what you need
overridePendingTransition(R.anim.stay, R.anim.stay)
//then start the new activity
R.anim.stay:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:duration="#android:integer/config_mediumAnimTime"/>
</set>

Related

Animation lagging after some time android

I have custom bottom menubar. I am trying to implement animation on view visible. my code is like below
Animation slideUp = AnimationUtils.loadAnimation(CardMainActivity.this, R.anim.slide_up);
ll_fonttextview.setAnimation(slideUp);
ll_fonttextview.setVisibility(View.VISIBLE);
and XML like this
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="100%"
android:toYDelta="0" />
</set>
Its working fine but after some click, its stop showing animation. I am not getting any error for that. Let me know if anyone have idea to fix it.
Thanks

Android Animation when change page

I am trying to switch from my "activity_main.xml" to a second .xml after a button click. I have already connected the button and put in setContentView(R.layout.view) and it works but I want it to animate. I want the view to come from the right and then the opposite when the user press back. I need a animation like a change of page in a book, I am doing this in eclipse if that helps.
I'm not sure how to get a "change of page in a book" animation, but here is how you would implement a slide in/slide out animation between activities which looks pretty good.
First, create two different XML files for the sliding animation. One for sliding in:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
...and one for sliding out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700" />
</set>
Now you can use these animations each time you press a button (or whatever your app does to move between activities) like so:
public void onClick(View v)
{
// set the animation to move once the button is clicked
overridePendingTransition(R.anim.slide_out, R.anim.slide_in);
Intent i = new Intent(MoveFromThisClass.this, MoveToThisCLass.class);
}
To move back to the previous class, just swap the slide_in and slide_out like this:
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
Hope this helps.
UPDATE (for the second part of your question):
"animation like a change of page in a book", i think you mean page curl annimation. if is that what you are looking for, you can use this library

Android: AlphaAnimation - no duration

I just want to create a fade out effect on a VideoView object.
The problem: Although I did set a certain duration for the animation, it looks like there's no duration. The VideoView object disappears immediately..
Things I've already tried:
AlphaAnimation anim = new AlphaAnimation(1, 0);
anim.setDuration(2000);
anim.setFillAfter(true);
mVideoView.setVisibility(View.VISIBLE);
mVideoView.startAnimation(anim);
the second try:
Animation anim = AnimationUtils.loadAnimation(this, R.anim.fadeout);
anim.setFillAfter(true);
mVideoView.startAnimation(anim);
in fadeout.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2000"
/>
</set>
I'd be glad if someone could help me here.
Ok, I'm not entirely sure VideoView supports this kind of animation.
I did a workaround by fading in a black ImageView object...yeah, it's not best solution.
But the effect is the same :D
Another way would be to create a screenshot, deactivate the VideoView and then to let the screenshot fade out.

Slide in another XML layout when button is clicked

I have a main.xml layout file and in my Java code, I am doing some calculation taken from the main layout and wanting to display in result.xml layout file. I know I can use the anim folder to hold the animation to slidei n the result layout like the following:
left to right:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
right to left:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700" />
</set>
I was wondering how to implement the above so when the button is clicked on the main layout file, the result layout file slides in from the right. And also if I wanted to go back to the main layout I can press a button (added on result layout) to slide right the main layout file
You can also use this function : overridePendingTransition which can define an animation for the upcoming activity and an other animation for the activity which exit.
Use it like this, in your second Activity :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(android.R.anim.slide_out_right, 0);
setContentView(R.layout.myLayout);
first argument is for the animation enter, and 0 is for no animation.
And for an animation when you leave your second activity :
#Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.enterAnim, R.anim.leaveAnim);
}
You can always use default stock animations supplied by Android framework.
Heres an example code:
boolean isFirstXml=evaluatingConditionFunction();
LayoutInflater inflator=getLayoutInflater();
View view=inflator.inflate(isFirstXml?R.layout.myfirstxml:R.layout.myseconxml, null, false);
view.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
setContentView(view);
Call this from any of your activity which holds your Parent View.
For custom animations you can visit developer docs. Heres the documentation link.

Sliding a view in android using animation

i Am trying to slide a whole view from RIght to left and left to right.
Here is the code
Utilities.vibrate(v.getContext());
Animation animation = AnimationUtils.loadAnimation(v.getContext(), R.anim.leave);
mainView.startAnimation(animation);
This will make it move from left to right.
Here is leave.xml code
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-90%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
It works fine however once the transition is done. It moves back to its original position. How can I make it stay at the slider position?
Add these lines after declaring your animation,
animation.setFillAfter(true);
animation.setFillEnabled(true);

Categories