I want to check if a View
within a ScrollView
is currently visible in Android. I am not checking if it is focused on yet but if it is currently being displayed on screen. Is there a method in View
that can tell me if the view is currently visible?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
This code works for me:
The
getVisibility()
method will help you to check the visibility of anyView
.Example:
or
Now use this location or rectangle to check if it is in your visible bounds or not. If it is simply the entire screen, check against
getResources().getDisplayMetrics()
.As pointed by Antek in the comments below, the view may still be gone or invisible with the returned values here telling where it was last drawn. So combining the above bounds-related condition with an
view.isShown()
orview.getVisibility() == VISIBLE
should take care of that.The function View.getVisibility() can have below values:
View.VISIBLE (0): the view is visible.
View.INVISIBLE (1): The view is invisible, but it still takes up space for layout purposes.
View.GONE (2): the view is gone. Completely hidden, as if the view had not been added
You can see below link for more info. How can I check if a view is visible or not in Android?
try