How to check if a button is visible during Activity creation?

Asked

Viewed 38 times

0

My screen has a button and a FAB that do the same thing and a scrollview, in case the scroll happens, I check if the button is visible or not, if it is visible, I hide the button. Okay, for the scroll, it works really well. My problem is during the creation of the view and if the screen content is small and the screen is very large, because there is no scroll and in this case, it does not hide the FAB. I’m trying to check if the button is visible right after the creation of the screen, but I did not succeed.

My method to check button visibility:

if (isViewVisible(binding.btnCall)) {
    binding.fabUpList.hide();
} else {
    binding.fabUpList.show();
}
private boolean isViewVisible(View view) {
    Rect mReact = new Rect();
    binding.nsvFreights.getHitRect(mReact);
    return view.getLocalVisibleRect(mReact);
}

As I see, right after the creation of the screen, whether a component is visible or not?

I tried to perform this check on onStart, onPostCreate and onResume and no option worked. Any suggestions?

  • Maybe using a Viewtreeobserver.Ongloballayoutlistener, see this reply

  • Solved, thank you very much!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.