setVisibility with sleep - android

I have this code:
result.setVisibility(0);
//a lot of code
//OnClick......
result.setVisibility(8);
SystemClock.sleep(500);
result.setVisibility(0);
So when i click a button the textView disappears and reappears to show that the result is changed.
But instead the textView "result" don't disappear and remains always visible. Why ?

I am not sure if the setVisibility function is at fault here. It appears that you are trying to sleep inside the UI code which happens to be a very commonplace mistake.
I am not sure but this willl help you.
Also I would recommend the usage of the pre defined constants VISIBLE , INVISIBLE and GONE instead of the integers.
Good Luck

Because you tell the thread that need to update the ui to go to sleep...
You should use animations for this stuff.

Related

How can I track if UI is fully drawed in Android?

From Activity lifecycle we know, that in onResume the UI is visible. But if I set a breakpoint on onResume, I still don't see it, only after that. I heard there's some method which can check it, but I can't remind how it calls. We used it to make better animation. So how can I be fully sured that UI is ready?
Add global layout listener on view you want to check. Also please make sure that you remove listener once your work is done else it will keep getting called multiple times.
#onik shared a good link that should solve your problem
This ensures lay-outing. Drawing happens continuously and frame are refreshed according to sys clock.
I recommend watching: https://www.youtube.com/watch?v=Q8m9sHdyXnE
This will give you good idea on android drawing and layouting

An elegant way to keep integrity of RelativeLayout when animating it?

Ok, so...
I know, there's been a real amount of questions about it, but it either didn't work, or was really fixed in a hard way. Oh, and that's my second day trying to do it, so please, accept my apologies about that and help me for Chet Haase's sake.
I have a button on top of a fragment, and a RecyclerView below it. When i press the button i want it to disappear and a new RelativeLayout with textfields to slide from the top.
I don't want to make it with animateLayoutChanges="true", cause it's not exactly what i was meant to do, and i want rather learn, than do it.
I tried to do it with widget.animate().translation... and the result was that one widget was just thrown in it's place when the rest of layout stood still. That's not what i meant to do.
I tried also to make an "new TranslateAnimation" since it has this "setFillAfter/Before" attribute... but that did not help me neither.
What i tried as well was to update the layout somehow adding to id margins and stuff (don't remember anymore, and i'm in work right now trying to figure it out, sorry) as it was described in some questions.
But none of that worked. I don't include code right now, cause i already tried to do it in some dozens of different ways.
Could you please tell me how to move a widget and make the rest of them to move with it? Is it possible?
I've already got it going once using setVisibility,animateLayoutChanges and animation combination, but that was massive and dirty as a baby duck.
Edit: oh, i almost forgot about it. Another problem is that when i animate/move a widget, only the rendering spod changes, but the real spot of it stays the same (ex. a onclicklistener)
Ok, me again.
I did it this way, that - let's say - i want to slide a button up and remove it.
So i animate it and all the other widgets (right, i can make a ViewGroup) up, put a listener on animation, and on "onAnimationEnd" i clear all the animations and set the visibility to GONE.
The animateLayoutChanges must be set to false
Still it's not what i wanted, so i'd be indebted to anyone who shows me another, better way.

android set a view to invisible and back to visible

I have a FrameLayout I want to disappear it on a button click and make it reappear on a button click
I tried this to disappear and it worked great
background.setVisibility(View.INVISIBLE);
background.invalidate();
but when I tried to get it back using the below code it didn't work.
background.setVisibility(View.VISIBLE);
background.invalidate();
What is the right way to do this?
check the thread on which you are executing these
just have a look at this example. This may help you!
And I think the method invalidate() invalidates the view (after invisible the view)and so it's not reverting back(invisible to visible).

Splash screen during async

I have an android app which does a lot of background processing on launch so for this I've set a content view with an indeterminate progress bar and then during async onprogressupdate I've set the text of the action being carried out. I would like to instead display my own splash screen with again a textview underneath where I can display the current action. I've researched into using surfaceviews and a thread - I'm not sure however if this is the best way to do this. I plan on displaying a sequence of pngs similar to a boot animation which loops until the async finishes.
So my question is: is a surface view class that implements the runnable the best way to accomplish this or is there a better way?
Thank you in advance!
I'm note quite sure about my answer but I guess surfaceview is a more reliable option for this task. If you use several PNGs instead then you need to cache them for memory purposes and this might cause a little problem for your invalidate method in your animation loop.
You could use a transparent activity as your splash screen which would allow you to do pretty much anything you want whilst it was displayed.
Went for AnimationDrawable in the end which was easy to use and worked amazingly. Credit to vmironov for the idea, unfortunately I can't accept a comment as an answer :(

In android, why will my button animation only clear from onClick()?

I wanted to animate a button, so I used this answer:
https://stackoverflow.com/a/4852468/559525
and got it animating on the first attempt. But then when I tried to stop the animation from various places in my application, I found that it will ONLY stop the animation if I call view.clearAnimation() from inside the onClick() callback.
My first guess is this has to do with multi threading synchronize issues, but I know about the UI thread and I was pretty sure I was calling the clearAnimation() method from approved places in the main UI thread.
My other thought was that the UI needed to be invalidated or refreshed? But I tried putting this call right before doing an invalidate on my main layout and that didn't help. I know my invalidate is working properly because it works to update other button attributes like color.
Thanks for any advice!

Categories

Resources