本文整理匯總了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);
}