本文整理汇总了Java中android.view.View.getTop方法的典型用法代码示例。如果您正苦于以下问题:Java View.getTop方法的具体用法?Java View.getTop怎么用?Java View.getTop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.getTop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findChildViewUnder
import android.view.View; //导入方法依赖的package包/类
public View findChildViewUnder(float x, float y) {
for (int i = this.mChildHelper.getChildCount() - 1; i >= 0; i--) {
View child = this.mChildHelper.getChildAt(i);
float translationX = ViewCompat.getTranslationX(child);
float translationY = ViewCompat.getTranslationY(child);
if (x >= ((float) child.getLeft()) + translationX && x <= ((float) child.getRight()) + translationX && y >= ((float) child.getTop()) + translationY && y <= ((float) child.getBottom()) + translationY) {
return child;
}
}
return null;
}
示例2: offsetChildAsNeeded
import android.view.View; //导入方法依赖的package包/类
private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
float offsetRange = dependency.getTop() + getFinalHeight() - child.getTop();
int headerOffsetRange = getHeaderOffsetRange();
if (dependency.getTranslationY() == headerOffsetRange) {
child.setTranslationY(offsetRange);
} else if (dependency.getTranslationY() == 0) {
child.setTranslationY(0);
} else {
child.setTranslationY((int) (dependency.getTranslationY() / (getHeaderOffsetRange() * 1.0f) * offsetRange));
}
}
示例3: initDefaultHeaderOffset
import android.view.View; //导入方法依赖的package包/类
private void initDefaultHeaderOffset(Rect headerMargins, RecyclerView recyclerView, View header, View firstView, int orientation) {
int translationX, translationY;
mDimensionCalculator.initMargins(mTempRect1, header);
ViewGroup.LayoutParams layoutParams = firstView.getLayoutParams();
int leftMargin = 0;
int topMargin = 0;
if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
leftMargin = marginLayoutParams.leftMargin;
topMargin = marginLayoutParams.topMargin;
}
if (orientation == LinearLayoutManager.VERTICAL) {
translationX = firstView.getLeft() - leftMargin + mTempRect1.left;
translationY = Math.max(
firstView.getTop() - topMargin - header.getHeight() - mTempRect1.bottom,
getListTop(recyclerView) + mTempRect1.top);
} else {
translationY = firstView.getTop() - topMargin + mTempRect1.top;
translationX = Math.max(
firstView.getLeft() - leftMargin - header.getWidth() - mTempRect1.right,
getListLeft(recyclerView) + mTempRect1.left);
}
headerMargins.set(translationX, translationY, translationX + header.getWidth(),
translationY + header.getHeight());
}
示例4: isOnTop
import android.view.View; //导入方法依赖的package包/类
public static boolean isOnTop(RecyclerView recyclerView, int loadingTriggerThreshold) {
final int firstVisiblePosition = getFirstVisibleItemPositionByLayoutManager(recyclerView.getLayoutManager());
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
final View viewByPosition = layoutManager.findViewByPosition(firstVisiblePosition);
if (viewByPosition != null) {
final int topPosition = viewByPosition.getTop();
return (topPosition == 0 && firstVisiblePosition == 0);
}
return false;
}
示例5: isFirstItemVisible
import android.view.View; //导入方法依赖的package包/类
private boolean isFirstItemVisible() {
final Adapter adapter = mRefreshableView.getAdapter();
if (null == adapter || adapter.isEmpty()) {
if (DEBUG) {
Log.d(LOG_TAG, "isFirstItemVisible. Empty View.");
}
return true;
} else {
/**
* This check should really just be:
* mRefreshableView.getFirstVisiblePosition() == 0, but PtRListView
* internally use a HeaderView which messes the positions up. For
* now we'll just add one to account for it and rely on the inner
* condition which checks getTop().
*/
if (mRefreshableView.getFirstVisiblePosition() <= 1) {
final View firstVisibleChild = mRefreshableView.getChildAt(0);
if (firstVisibleChild != null) {
return firstVisibleChild.getTop() >= mRefreshableView.getTop();
}
}
}
return false;
}
示例6: isViewUnder
import android.view.View; //导入方法依赖的package包/类
public boolean isViewUnder(View view, int x, int y) {
if (view != null && x >= view.getLeft() && x < view.getRight() && y >= view.getTop() && y
< view.getBottom()) {
return true;
}
return false;
}
示例7: getScreenCoordsForPos
import android.view.View; //导入方法依赖的package包/类
private float[] getScreenCoordsForPos(int line, int pos)
{
LayoutManager manager = getLayoutManager();
ViewHolder holder = findViewHolderForAdapterPosition(line);
if(holder == null)
{
if(getChildCount() > 0 && getChildAdapterPosition(getChildAt(getChildCount() - 1)) < line)
return new float[]{getWidth() / 2, getHeight(), 0};
return new float[]{getWidth() / 2, 0, 0};
}
View view = manager.findViewByPosition(findViewHolderForAdapterPosition(line).getLayoutPosition());
if(view == null)
return new float[]{0, 0, 0};
Layout layout = ((TextView)view).getLayout();
float x = layout.getPrimaryHorizontal(pos);
int ln = layout.getLineForOffset(pos);
float y = (float)(layout.getLineTop(ln) + layout.getLineBottom(ln)) / 2;
float screenX = x + view.getLeft() + getScrollX();
float screenY = y + view.getTop() + getScrollY();
if(screenY < 0)
screenY = 0;
if(screenY > getBottom())
screenY = getBottom();
return new float[]{screenX, screenY, layout.getLineBottom(ln) - y};
}
示例8: scrollTo
import android.view.View; //导入方法依赖的package包/类
/**
* 将targetView滚到最顶端
*/
public void scrollTo(View targetView) {
int oldScrollY = getScrollY();
int top = targetView.getTop() - mTop;
int delatY = top - oldScrollY;
lastScrollDelta = delatY;
overScrollBy(0, delatY, 0, getScrollY(), 0, getScrollRange(), 0, 0,
true);
}
示例9: onViewReleased
import android.view.View; //导入方法依赖的package包/类
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
int top;
@State int targetState;
if (mHideable && shouldHide(releasedChild, yvel)) {
top = mParentHeight;
targetState = STATE_HIDDEN;
} else if (yvel <= 0.f) {
int currentTop = releasedChild.getTop();
if (Math.abs(currentTop - mAnchorOffset) < Math.abs(currentTop - mMinOffset)) {
top = mAnchorOffset;
targetState = STATE_ANCHOR;
} else if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) {
top = mMinOffset;
targetState = STATE_EXPANDED;
} else {
top = mMaxOffset;
targetState = STATE_COLLAPSED;
}
} else {
top = mMaxOffset;
targetState = STATE_COLLAPSED;
}
if (mViewDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top)) {
setStateInternal(STATE_SETTLING);
ViewCompat.postOnAnimation(releasedChild, new SettleRunnable(releasedChild, targetState));
} else {
setStateInternal(targetState);
}
}
示例10: getViewPosition
import android.view.View; //导入方法依赖的package包/类
private static void getViewPosition(View view, Point p) {
p.x += view.getLeft();
p.y += view.getTop();
if (view.getParent() != null && view.getParent() instanceof View) {
getViewPosition((View) view.getParent(), p);
}
}
示例11: onDraw
import android.view.View; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
c.save();
int left, right, top, bottom;
int count = parent.getChildCount();
if (!mBuilder.isShowLastDivider) {
count -= 1;
}
Context context = parent.getContext();
for (int i = 0; i < count; i++) {
final View child = parent.getChildAt(i);
int transitionX = (int) ViewCompat.getTranslationX(child);
int transitionY = (int) ViewCompat.getTranslationY(child);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
if (mBuilder.orientation == LinearLayoutManager.VERTICAL) {
left = child.getLeft() - params.leftMargin + transitionX + ViewUtil.dp2px(context, mBuilder.leftMargin);
top = child.getBottom() + params.bottomMargin;
right = child.getRight() + params.rightMargin - ViewUtil.dp2px(context, mBuilder.rightMargin);
bottom = top + mBuilder.dividerHeight + transitionY;
} else {
top = child.getTop() - params.topMargin + ViewUtil.dp2px(context, mBuilder.topMargin);
bottom = child.getBottom() + params.bottomMargin + transitionY - ViewUtil.dp2px(context, mBuilder.bottomMargin);
left = child.getRight() + params.rightMargin + transitionX;
right = left + mBuilder.dividerHeight;
}
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
c.restore();
}
开发者ID:crazysunj,项目名称:RecycylerViewItemDecoration,代码行数:35,代码来源:LinearLayoutDividerItemDecoration.java
示例12: findSwapTargets
import android.view.View; //导入方法依赖的package包/类
private List<ViewHolder> findSwapTargets(ViewHolder viewHolder) {
if (this.mSwapTargets == null) {
this.mSwapTargets = new ArrayList();
this.mDistances = new ArrayList();
} else {
this.mSwapTargets.clear();
this.mDistances.clear();
}
int margin = this.mCallback.getBoundingBoxMargin();
int left = Math.round(this.mSelectedStartX + this.mDx) - margin;
int top = Math.round(this.mSelectedStartY + this.mDy) - margin;
int right = (viewHolder.itemView.getWidth() + left) + (margin * 2);
int bottom = (viewHolder.itemView.getHeight() + top) + (margin * 2);
int centerX = (left + right) / 2;
int centerY = (top + bottom) / 2;
LayoutManager lm = this.mRecyclerView.getLayoutManager();
int childCount = lm.getChildCount();
for (int i = 0; i < childCount; i++) {
View other = lm.getChildAt(i);
if (other != viewHolder.itemView && other.getBottom() >= top && other.getTop() <= bottom && other.getRight() >= left && other.getLeft() <= right) {
ViewHolder otherVh = this.mRecyclerView.getChildViewHolder(other);
if (this.mCallback.canDropOver(this.mRecyclerView, this.mSelected, otherVh)) {
int dx = Math.abs(centerX - ((other.getLeft() + other.getRight()) / 2));
int dy = Math.abs(centerY - ((other.getTop() + other.getBottom()) / 2));
int dist = (dx * dx) + (dy * dy);
int pos = 0;
int cnt = this.mSwapTargets.size();
int j = 0;
while (j < cnt && dist > ((Integer) this.mDistances.get(j)).intValue()) {
pos++;
j++;
}
this.mSwapTargets.add(pos, otherVh);
this.mDistances.add(pos, Integer.valueOf(dist));
}
}
}
return this.mSwapTargets;
}
示例13: getTargetY
import android.view.View; //导入方法依赖的package包/类
private int getTargetY() {
final int first = getFirstVisiblePosition();
final int otherAdjust = (mItemHeightCollapsed + getDividerHeight()) / 2;
View v = getChildAt(mDropPos - first);
int targetY = -1;
if (v != null) {
if (mDropPos == srcPos) {
targetY = v.getTop();
} else if (mDropPos < srcPos) {
// expanded down
targetY = v.getTop() - otherAdjust;
} else {
// expanded up
targetY = v.getBottom() + otherAdjust - mFloatViewHeight;
}
} else {
// drop position is not on screen?? no animation
cancel();
}
return targetY;
}
示例14: getAppBarChildOnOffset
import android.view.View; //导入方法依赖的package包/类
private static View getAppBarChildOnOffset(final AppBarLayout layout, final int offset) {
final int absOffset = Math.abs(offset);
for (int i = 0, z = layout.getChildCount(); i < z; i++) {
final View child = layout.getChildAt(i);
if (absOffset >= child.getTop() && absOffset <= child.getBottom()) {
return child;
}
}
return null;
}
示例15: onTouchEvent
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
if ((mDragListener != null || mDropListener != null) && mDragView != null) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
Rect r = mTempRect;
mDragView.getDrawingRect(r);
stopDragging();
if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
mDropListener.drop(mFirstDragPos, mDragPos);
}
unExpandViews(false);
break;
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
int x = (int) ev.getX();
int y = (int) ev.getY();
dragView(x, y);
int itemnum = getItemForPosition(y);
if (itemnum >= 0) {
if (action == MotionEvent.ACTION_DOWN || itemnum != mDragPos) {
if (mDragListener != null) {
mDragListener.drag(mDragPos, itemnum);
}
mDragPos = itemnum;
doExpansion();
}
int speed = 0;
adjustScrollBounds(y);
if (y > mLowerBound) {
// scroll the list up a bit
speed = y > (mHeight + mLowerBound) / 2 ? 16 : 4;
} else if (y < mUpperBound) {
// scroll the list down a bit
speed = y < mUpperBound / 2 ? -16 : -4;
}
if (speed != 0) {
int ref = pointToPosition(0, mHeight / 2);
if (ref == AdapterView.INVALID_POSITION) {
// we hit a divider or an invisible view, check
// somewhere else
ref = pointToPosition(0, mHeight / 2 + getDividerHeight() + 64);
}
View v = getChildAt(ref - getFirstVisiblePosition());
if (v != null) {
int pos = v.getTop();
setSelectionFromTop(ref, pos - speed);
}
}
}
break;
default:
break;
}
return true;
}
return super.onTouchEvent(ev);
}