本文整理汇总了Java中android.view.View.getLocalVisibleRect方法的典型用法代码示例。如果您正苦于以下问题:Java View.getLocalVisibleRect方法的具体用法?Java View.getLocalVisibleRect怎么用?Java View.getLocalVisibleRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.getLocalVisibleRect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVisiblePercent
import android.view.View; //导入方法依赖的package包/类
public int getVisiblePercent(View v) {
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (v.getLocalVisibleRect(scrollBounds)) {
// Any portion of the imageView, even a single pixel, is within the visible window
} else {
// NONE of the imageView is within the visible window
return -1;
}
if (v.isShown()) {
Rect r = new Rect();
v.getGlobalVisibleRect(r);
double sVisible = r.width() * r.height();
double sTotal = v.getWidth() * v.getHeight();
MyLg.e(TAG, "sVisible " + sVisible + " sTotal" + sTotal);
return (int) (100 * sVisible / sTotal) - 20;
} else {
return -1;
}
}
示例2: getVisibilityPercents
import android.view.View; //导入方法依赖的package包/类
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;
}
示例3: onTouch
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
updateBackground(pressedDrawable);
this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom);
break;
case MotionEvent.ACTION_MOVE:
Rect r = new Rect();
view.getLocalVisibleRect(r);
if (!r.contains((int) motionEvent.getX(), (int) motionEvent.getY() + 3 * mShadowHeight) &&
!r.contains((int) motionEvent.getX(), (int) motionEvent.getY() - 3 * mShadowHeight)) {
updateBackground(unpressedDrawable);
this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
}
break;
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
updateBackground(unpressedDrawable);
this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
break;
}
return false;
}
示例4: getTheVisibileView
import android.view.View; //导入方法依赖的package包/类
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;
}
示例5: getScreenVisibleRect
import android.view.View; //导入方法依赖的package包/类
/**
* @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;
}
示例6: checkVisibility
import android.view.View; //导入方法依赖的package包/类
public static int checkVisibility(View view){
Rect rect = new Rect();
boolean b = view.getLocalVisibleRect(rect);
LogUtil.d("VisibilityCheck", view.getClass().getSimpleName()+": "+ b +" "+view.getWidth()+view.getHeight()+" "+rect.toString());
if(b){
if(rect.width()==view.getMeasuredWidth() && rect.height()== view.getMeasuredHeight()){//这里用完全可见,也可调节比例
return ALL_VISIBLE;
}
return PART_VISIBLE;
}
return ALL_INVISIBLE;
}
示例7: isVisibleInScreen
import android.view.View; //导入方法依赖的package包/类
/**
* is the target view visible in local coordinate.
*
* @param view the target view
* @return true if visible.(visible means the view's all side can see).
*/
public static boolean isVisibleInScreen(View view) {
if (view == null) {
throw new NullPointerException();
}
DisplayMetrics dm = new DisplayMetrics();
WindowManager wm = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(dm);
return view.getLocalVisibleRect(new Rect(0, 0, dm.widthPixels, dm.heightPixels));
}
示例8: isViewVisible
import android.view.View; //导入方法依赖的package包/类
public boolean isViewVisible() {
View view = mAwareChild.getHostView();
return view != null && view.getLocalVisibleRect(mVisibleRect);
}