本文整理了Java中android.view.View.getLocalVisibleRect()
方法的一些代码示例,展示了View.getLocalVisibleRect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。View.getLocalVisibleRect()
方法的具体详情如下:
包路径:android.view.View
类名称:View
方法名:getLocalVisibleRect
暂无
代码示例来源:origin: florent37/MaterialViewPager
static View getTheVisibileView(List<View> viewList) {
Rect scrollBounds = new Rect();
int listSize = viewList.size();
for (int i = 0; i < listSize; ++i) {
View view = viewList.get(i);
if (view != null) {
view.getHitRect(scrollBounds);
if (view.getLocalVisibleRect(scrollBounds)) {
return view;
}
}
}
return null;
}
}
代码示例来源:origin: airbnb/epoxy
/**
* Update the visibility item according the current layout.
*
* @param view the current {@link com.airbnb.epoxy.EpoxyViewHolder}'s itemView
* @param parent the {@link androidx.recyclerview.widget.RecyclerView}
* @return true if the view has been measured
*/
boolean update(@NonNull View view, @NonNull RecyclerView parent, boolean detachEvent) {
// Clear the rect before calling getLocalVisibleRect
localVisibleRect.setEmpty();
boolean viewDrawn = view.getLocalVisibleRect(localVisibleRect) && !detachEvent;
height = view.getHeight();
width = view.getWidth();
viewportHeight = parent.getHeight();
viewportWidth = parent.getWidth();
visibleHeight = viewDrawn ? localVisibleRect.height() : 0;
visibleWidth = viewDrawn ? localVisibleRect.width() : 0;
return height > 0 && width > 0;
}
代码示例来源:origin: huburt-Hu/NewbieGuide
@Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
// if (scrollView.getScrollY() + scrollView.getHeight() -
// scrollView.getPaddingTop() - scrollView.getPaddingBottom()
// == scrollView.getChildAt(0).getHeight()) {//判断滑动到底部
// LogUtil.i("call show");
// controller.show();
// }
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (lightNext.getLocalVisibleRect(scrollBounds)) {
controller.show();
}
}
});
代码示例来源:origin: stackoverflow.com
if (imgContainer.getLocalVisibleRect(scrollBounds)) {
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics ();
代码示例来源:origin: Naoki2015/CircleDemo
/**
* When this method is called, the implementation should provide a visibility percents in range 0 - 100 %
* @param view the view which visibility percent should be calculated.
* Note: visibility doesn't have to depend on the visibility of a full view.
* It might be calculated by calculating the visibility of any inner View
*
* @return percents of visibility
*/
public static int getVisibilityPercents(View view) {
final Rect currentViewRect = new Rect();
int percents = 100;
int height = (view == null || view.getVisibility() != View.VISIBLE) ? 0 : view.getHeight();
if (height == 0) {
return 0;
}
view.getLocalVisibleRect(currentViewRect);
if(viewIsPartiallyHiddenTop(currentViewRect)){
// view is partially hidden behind the top edge
percents = (height - currentViewRect.top) * 100 / height;
} else if(viewIsPartiallyHiddenBottom(currentViewRect, height)){
percents = currentViewRect.bottom * 100 / height;
}
return percents;
}
代码示例来源:origin: weexteam/weex-hackernews
public boolean isViewVisible() {
View view = mAwareChild.getHostView();
return view != null && view.getLocalVisibleRect(mVisibleRect);
}
}
代码示例来源:origin: waynell/VideoListPlayer
if(view.getLocalVisibleRect(currentViewRect)) {
代码示例来源:origin: willowtreeapps/Hyperion-Android
attributes.add(new ViewAttribute<>("GlobalBottom", String.valueOf(rect.bottom)));
view.getLocalVisibleRect(rect);
代码示例来源:origin: Nipuream/NRecyclerView
public Rect getLocalRectPosition(View view){
if(view != null)
{
view.getLocalVisibleRect(rect);
return rect;
}else
rect = new Rect();
return rect;
}
代码示例来源:origin: sangxiaonian/AliBehaver
/**
* 获取View在屏幕中的位置
* @param view
* @return
*/
public static Rect getViewRect(View view){
Rect rect = new Rect();
view.getLocalVisibleRect(rect);
return rect;
}
代码示例来源:origin: stackoverflow.com
View view01 = findViewById(R.id.View01);
view01.post(new Runnable() {
@Override
public void run() {
view01.getLocalVisibleRect(rectf);
Log.d("WIDTH :", String.valueOf(rectf.width()));
Log.d("HEIGHT :", String.valueOf(rectf.height()));
Log.d("left :", String.valueOf(rectf.left));
Log.d("right :", String.valueOf(rectf.right));
Log.d("top :", String.valueOf(rectf.top));
Log.d("bottom :", String.valueOf(rectf.bottom));
}
});
代码示例来源:origin: derry/delion
/**
* @return Visible rect in screen coordinates for the given View.
*/
private Rect getScreenVisibleRect(View view) {
view.getLocalVisibleRect(mScreenVisibleRect);
view.getLocationOnScreen(mScreenVisiblePoint);
mScreenVisibleRect.offset(mScreenVisiblePoint[0], mScreenVisiblePoint[1]);
return mScreenVisibleRect;
}
代码示例来源:origin: alexjlockwood/adp-activity-transitions
/**
* Returns true if {@param view} is contained within {@param container}'s bounds.
*/
private static boolean isViewInBounds(@NonNull View container, @NonNull View view) {
Rect containerBounds = new Rect();
container.getHitRect(containerBounds);
return view.getLocalVisibleRect(containerBounds);
}
}
代码示例来源:origin: xbmc/Kore
/**
* Returns true if {@param view} is visible within {@param container}'s bounds.
*/
public static boolean isViewInBounds(@NonNull View container, @NonNull View view) {
Rect containerBounds = new Rect();
container.getHitRect(containerBounds);
return view.getLocalVisibleRect(containerBounds);
}
代码示例来源:origin: stackoverflow.com
public static boolean isViewVisible(View subView, View parentView) {
Rect scrollBounds = new Rect();
parentView.getHitRect(scrollBounds);
if (subView.getLocalVisibleRect(scrollBounds)) {
return true;
}
return false;
}
代码示例来源:origin: r17171709/android_demo
private boolean checkTouch(int x, int y) {
Rect rect=new Rect();
getChildAt(1).getLocalVisibleRect(rect);
int left = rect.left;
int top = lastShowPos;
int right = rect.right;
int bottom = lastShowPos+rect.bottom;
if (x>=left && x<=right && y>=top && y<bottom) {
return true;
}
else {
return false;
}
}
代码示例来源:origin: Wilm0r/giggity
@Override
public void onScrollChanged() {
Rect scrollBounds = new Rect();
scr.getHitRect(scrollBounds);
View subHeader = root.findViewById(R.id.subHeader);
View header = root.findViewById(R.id.header);
app_.setShadow(header, !subHeader.getLocalVisibleRect(scrollBounds));
app_.setShadow(subHeader, subHeader.getLocalVisibleRect(scrollBounds));
}
});
代码示例来源:origin: stackoverflow.com
public static void scrollToView(final ScrollView scrollView, final View view) {
// View needs a focus
view.requestFocus();
// Determine if scroll needs to happen
final Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (!view.getLocalVisibleRect(scrollBounds)) {
new Handler().post(new Runnable() {
@Override
public void run() {
scrollView.smoothScrollTo(0, view.getBottom());
}
});
}
}
代码示例来源:origin: tohodog/QSVideoPlayer
private int getVisibilityPercents(View view) {
final Rect currentViewRect = new Rect();
int percents = 100;
int height = (view == null || view.getVisibility() != View.VISIBLE) ? 0 : view.getHeight();
if (height == 0) {
return 0;
}
view.getLocalVisibleRect(currentViewRect);
if (viewIsPartiallyHiddenTop(currentViewRect)) {
// view is partially hidden behind the top edge
percents = (height - currentViewRect.top) * 100 / height;
} else if (viewIsPartiallyHiddenBottom(currentViewRect, height)) {
percents = currentViewRect.bottom * 100 / height;
}
return percents;
}
代码示例来源:origin: Unity-Technologies/unity-ads-android
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
float alpha = 1.0f;
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
alpha = getAlpha();
}
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_RESIZED, left, top, right, bottom, alpha);
if (getParent() != null) {
// Given our current rect, check that we are still able to be seen in the parent.
Rect rect = new Rect();
getHitRect(rect);
if (getParent() instanceof View) {
if (!((View) getParent()).getLocalVisibleRect(rect)) {
onVisibilityChanged(this, View.GONE);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!