本文整理汇总了Java中android.support.v4.view.ViewCompat.getTranslationY方法的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.getTranslationY方法的具体用法?Java ViewCompat.getTranslationY怎么用?Java ViewCompat.getTranslationY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewCompat
的用法示例。
在下文中一共展示了ViewCompat.getTranslationY方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: animateMove
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY,
int toX, int toY) {
final View view = holder.itemView;
fromX += ViewCompat.getTranslationX(holder.itemView);
fromY += ViewCompat.getTranslationY(holder.itemView);
resetAnimation(holder);
int deltaX = toX - fromX;
int deltaY = toY - fromY;
if (deltaX == 0 && deltaY == 0) {
dispatchMoveFinished(holder);
return false;
}
if (deltaX != 0) {
ViewCompat.setTranslationX(view, -deltaX);
}
if (deltaY != 0) {
ViewCompat.setTranslationY(view, -deltaY);
}
mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
return true;
}
示例2: findHeaderViewUnder
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* 配合使用点击事件等
*
* @param x
* @param y
* @return
*/
public View findHeaderViewUnder(float x, float y) {
for (int i = 0, n = mHeaderCache.size(); i < n; i++) {
RecyclerView.ViewHolder holder = mHeaderCache.valueAt(i);
final View child = holder.itemView;
final float translationX = ViewCompat.getTranslationX(child);
final float translationY = ViewCompat.getTranslationY(child);
if (x >= child.getLeft() + translationX &&
x <= child.getRight() + translationX &&
y >= child.getTop() + translationY &&
y <= child.getBottom() + translationY) {
return child;
}
}
return null;
}
示例3: animateMove
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
int toX, int toY) {
final View view = holder.itemView;
fromX += ViewCompat.getTranslationX(holder.itemView);
fromY += ViewCompat.getTranslationY(holder.itemView);
resetAnimation(holder);
int deltaX = toX - fromX;
int deltaY = toY - fromY;
if (deltaX == 0 && deltaY == 0) {
dispatchMoveFinished(holder);
return false;
}
if (deltaX != 0) {
ViewCompat.setTranslationX(view, -deltaX);
}
if (deltaY != 0) {
ViewCompat.setTranslationY(view, -deltaY);
}
mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
return true;
}
示例4: updateFabTranslationForSnackbar
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void updateFabTranslationForSnackbar(CoordinatorLayout parent, final FloatingActionButton fab, View snackbar) {
float targetTransY = getFabTranslationYForSnackbar(parent, fab);
if (this.mFabTranslationY != targetTransY) {
float currentTransY = ViewCompat.getTranslationY(fab);
if (this.mFabTranslationYAnimator != null && this.mFabTranslationYAnimator.isRunning()) {
this.mFabTranslationYAnimator.cancel();
}
if (!fab.isShown() || Math.abs(currentTransY - targetTransY) <= ((float) fab.getHeight()) * 0.667f) {
ViewCompat.setTranslationY(fab, targetTransY);
} else {
if (this.mFabTranslationYAnimator == null) {
this.mFabTranslationYAnimator = ViewUtils.createAnimator();
this.mFabTranslationYAnimator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
this.mFabTranslationYAnimator.setUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimatorCompat animator) {
ViewCompat.setTranslationY(fab, animator.getAnimatedFloatValue());
}
});
}
this.mFabTranslationYAnimator.setFloatValues(currentTransY, targetTransY);
this.mFabTranslationYAnimator.start();
}
this.mFabTranslationY = targetTransY;
}
}
示例5: animateToolbar
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void animateToolbar(final float toY) {
float layoutTranslationY = ViewCompat.getTranslationY(mInterceptionLayout);
if (layoutTranslationY != toY) {
ValueAnimator animator = ValueAnimator.ofFloat(ViewCompat.getTranslationY(mInterceptionLayout), toY).setDuration(200);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float translationY = (float) animation.getAnimatedValue();
View tView = adjustmentToolBarView();
ViewCompat.setTranslationY(mInterceptionLayout, translationY);
ViewCompat.setTranslationY(tView, translationY);
if (translationY < 0) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams();
lp.height = (int) (-translationY + getScreenHeight());
mInterceptionLayout.requestLayout();
}
}
});
animator.start();
}
}
示例6: onScrollChanged
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
if (dragging) {
int headerBannerHeight = headerBanner.getHeight();
float currentHeaderTranslationY = ViewCompat.getTranslationY(mHeaderContainer);
if (firstScroll) {
if (-headerBannerHeight < currentHeaderTranslationY) {
mBaseTranslationY = scrollY;
}
}
final float headerTranslationY = ScrollUtils.getFloat(mBaseTranslationY - scrollY, -headerBannerHeight, 0);
ViewCompat.animate(mHeaderContainer).cancel();
ViewCompat.setTranslationY(mHeaderContainer, headerTranslationY);
//todo: need some more works on this
setpagertoppadding(totalfullheight - headerTranslationY);
}
}
示例7: onDraw
import android.support.v4.view.ViewCompat; //导入方法依赖的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
示例8: scrollToClosed
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public void scrollToClosed(int duration) {
float curTranslationY = ViewCompat.getTranslationY(mLayout);
float dy = getHeaderOffsetRange() - curTranslationY;
if (BuildConfig.DEBUG) {
Log.d(TAG, "scrollToClosed:offest:" + getHeaderOffsetRange());
Log.d(TAG, "scrollToClosed: cur0:" + curTranslationY + ",end0:" + dy);
Log.d(TAG, "scrollToClosed: cur:" + Math.round(curTranslationY) + ",end:" + Math.round(dy));
Log.d(TAG, "scrollToClosed: cur1:" + (int) (curTranslationY) + ",end:" + (int) dy);
}
mOverScroller.startScroll(0, Math.round(curTranslationY - 0.1f), 0, Math.round(dy + 0.1f), duration);
start();
}
示例9: updateScrollingForSnackbar
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void updateScrollingForSnackbar(View dependency, V child, boolean enabled) {
if (dependency instanceof Snackbar.SnackbarLayout) {
scrollingEnabled = enabled;
if (!hideAlongSnackbar && ViewCompat.getTranslationY(child) != 0) {
ViewCompat.setTranslationY(child, 0);
hidden = false;
hideAlongSnackbar = true;
} else if (hideAlongSnackbar) {
hidden = true;
animateOffset(child, -child.getHeight());
}
}
}
示例10: update
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public void update() {
if (this.mStartDx == this.mTargetX) {
this.mX = ViewCompat.getTranslationX(this.mViewHolder.itemView);
} else {
this.mX = this.mStartDx + (this.mFraction * (this.mTargetX - this.mStartDx));
}
if (this.mStartDy == this.mTargetY) {
this.mY = ViewCompat.getTranslationY(this.mViewHolder.itemView);
} else {
this.mY = this.mStartDy + (this.mFraction * (this.mTargetY - this.mStartDy));
}
}
示例11: update
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* We run updates on onDraw method but use the fraction from animator callback.
* This way, we can sync translate x/y values w/ the animators to avoid one-off frames.
*/
public void update() {
if (mStartDx == mTargetX) {
mX = ViewCompat.getTranslationX(mViewHolder.itemView);
} else {
mX = mStartDx + mFraction * (mTargetX - mStartDx);
}
if (mStartDy == mTargetY) {
mY = ViewCompat.getTranslationY(mViewHolder.itemView);
} else {
mY = mStartDy + mFraction * (mTargetY - mStartDy);
}
}
示例12: animateAdd
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateAdd(final RecyclerView.ViewHolder holder) {
if (adapter == null) {
adapter = (ChannelAdapter) rv.getAdapter();
}
int adapterPosition=holder.getAdapterPosition();
int type=adapter.getItemViewType(adapterPosition);
int position=0;
ShortcutMenuBean shortcutMenuBean;
switch (type) {
case ChannelAdapter.TYPE_MY:
case ChannelAdapter.TYPE_OTHER:
if (type == ChannelAdapter.TYPE_MY) {
position = adapterPosition - ChannelAdapter.getCountPreMyHeader();
shortcutMenuBean = adapter.getMyChannelItems().get(position);
} else {
position = adapterPosition - ChannelAdapter.getCountPreOtherHeader() - adapter.getMyChannelItems().size();
shortcutMenuBean = adapter.getOtherChannelItems().get(position);
}
if (shortcutMenuBean.isMove()) {
View view=holder.itemView;
if (type == ChannelAdapter.TYPE_MY) {
view.bringToFront();
}
int toX=view.getLeft();
int toY=holder.itemView.getTop();
ShortcutMenuBean.MoveInfo moveInfo=shortcutMenuBean.getMoveInfo();
int fromX=moveInfo.getFromX();
int fromY = moveInfo.getFromY();
fromX += ViewCompat.getTranslationX(holder.itemView);
fromY += ViewCompat.getTranslationY(holder.itemView);
resetAnimation(holder);
int deltaX = toX - fromX;
int deltaY = toY - fromY;
if (deltaX == 0 && deltaY == 0) {
dispatchMoveFinished(holder);
return false;
}
if (deltaX != 0) {
ViewCompat.setTranslationX(view, -deltaX);
}
if (deltaY != 0) {
ViewCompat.setTranslationY(view, -deltaY);
}
mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
shortcutMenuBean.setMoveInfo(null);
return true;
}
break;
}
resetAnimation(holder);
ViewCompat.setAlpha(holder.itemView, 0);
mPendingAdditions.add(holder);
return true;
}
示例13: shouldInterceptTouchEvent
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
if (!mScrolled && mSlop < Math.abs(diffX) && Math.abs(diffY) < Math.abs(diffX)) {
// Horizontal scroll is maybe handled by ViewPager
return false;
}
Scrollable scrollable = getCurrentScrollable();
if (scrollable == null) {
mScrolled = false;
return false;
}
// If interceptionLayout can move, it should intercept.
// And once it begins to move, horizontal scroll shouldn't work any longer.
// View toolbarView = getActivity().findViewById(R.id.toolbar);
int headerBannerHeight = headerBanner.getHeight();
int translationY = (int) ViewCompat.getTranslationY(mInterceptionLayout);
boolean scrollingUp = 0 < diffY;
boolean scrollingDown = diffY < 0;
if (scrollingUp) {
if (translationY < 0) {
mScrolled = true;
mLastScrollState = ObservableScrollState.UP;
return true;
}
} else if (scrollingDown) {
if (-headerBannerHeight < translationY) {
mScrolled = true;
mLastScrollState = ObservableScrollState.DOWN;
return true;
}
}
mScrolled = false;
return false;
}
示例14: onMove
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public void onMove(float y, float yDx) {
float headerTranslationY = ViewCompat.getTranslationY(this.headerLayout) + yDx;
if (headerTranslationY >= 0.0f) {
headerExpand(0);
} else if (headerTranslationY <= ((float) (-this.mHeaderHeight))) {
headerFold(0);
} else {
ViewCompat.animate(this.headerLayout).translationY(headerTranslationY).setDuration(0)
.start();
ViewCompat.animate(this.frameContent).translationY(((float) this.mHeaderHeight) +
headerTranslationY).setDuration(0).start();
}
}
示例15: drawVerticalOrientationDividers
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
void drawVerticalOrientationDividers(Canvas c, RecyclerView parent,
RecyclerView.LayoutManager layoutManager) {
LinearLayoutManager manager = (LinearLayoutManager) layoutManager;
int childCount = parent.getChildCount();
float left, top, right, bottom;
for (int i = 0; i < childCount; i++) {
View view = parent.getChildAt(i);
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) view.getLayoutParams();
int position = lp.getViewAdapterPosition();
if (position < 0 || !mProvider.isDividerNeedDraw(position))
continue;
float transitionX = ViewCompat.getTranslationX(view);
float transitionY = ViewCompat.getTranslationY(view);
left = view.getLeft() - lp.leftMargin + transitionX + mProvider.marginStart(position);
right = view.getRight() + lp.rightMargin + transitionX - mProvider.marginEnd(position);
IDivider divider = mProvider.createDivider(position);
if (manager.getReverseLayout()) {
if (divider.getType() == IDivider.TYPE_DRAWABLE) {
bottom = view.getTop() - lp.topMargin + transitionY;
top = bottom - divider.getDividerSize();
} else {
top = view.getTop() - lp.topMargin - divider.getDividerSize() / 2f + transitionY;
bottom = top;
}
if (mDrawInsideEachOfItem) {
top += divider.getDividerSize();
bottom += divider.getDividerSize();
}
} else {
if (divider.getType() == IDivider.TYPE_DRAWABLE) {
top = view.getBottom() + lp.bottomMargin + transitionY;
bottom = top + divider.getDividerSize();
} else {
top = view.getBottom() + lp.bottomMargin + divider.getDividerSize() / 2f + transitionY;
bottom = top;
}
if (mDrawInsideEachOfItem) {
top -= divider.getDividerSize();
bottom -= divider.getDividerSize();
}
}
divider.draw(c, left, top, right, bottom);
}
}