How to Force an Entire Layout View Refresh

force layout to refresh/repaint android?

Maybe you need:

linear.invalidate();
linear.requestLayout();

after making the layout changes.

EDIT:

Run the code on a different thread:

new Thread() {
@Override
public void run() {
<your code here>
}
}.start();

And whenever you need to update the UI from that thread use:

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
<code to change UI>
}
});

How to force a view to redraw immediately before the next line of code is executed

Okay, I finally found a solution to this issue, and it's simple. It seems that the problem was just that I was executing the drawable changes in an OnClickLIstener, when I should have been doing it in an OnTouchListener. If I set an OnTouchListener for my button that looks for ACTION_DOWN and then runs setBackgroundColor on its parent layout, the change occurs immediately.

An alternative, less robust solution comes from this post. You can assign a selector for the parent layout background in xml, then in the OnTouchListener mentioned above, run setPressed(true) on that layout. It's not a great solution because the selector gives you a lot less freedom than directly changing the view's properties in code. You couldn't set the layout background to a different color by pressing a different button, for example.

Thanks to those who helped out with suggestions on this!

Android Studio Refresh Layout without Rebuilding Project

According to: Android Studio: How to 'Refresh' after adding file?

There is no refresh option for do that on AndroidStudio

There is only an option for Make project in Build -> Build Project.

But, i think this option will do the refresh option:

File->Synchronize. Or equivalently, Ctrl+Alt+Y or the little circle with arrows menu button.

Update: In the new Android Studio, This feature is available. Thanks to jason.

How to refresh a view in Android

This is not the right way but I think it should do the job for simple cases:-

Restart your activity without animation.

finish();
startActivity(new Intent(this, MyActivity.class));
overridePendingTransition(0, 0);


Related Topics



Leave a reply



Submit