本文整理汇总了Java中android.support.v4.view.ViewCompat.getTranslationX方法的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.getTranslationX方法的具体用法?Java ViewCompat.getTranslationX怎么用?Java ViewCompat.getTranslationX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewCompat
的用法示例。
在下文中一共展示了ViewCompat.getTranslationX方法的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);
int deltaX = toX - fromX;
int deltaY = toY - fromY;
if (deltaX == 0 && deltaY == 0) {
dispatchMoveFinished(holder);
return false;
}
resetAnimation(holder);
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: 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;
}
示例3: findChildViewUnder
import android.support.v4.view.ViewCompat; //导入方法依赖的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;
}
示例4: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
if (oldHolder == newHolder) {
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (((float) (toX - fromX)) - prevTranslationX);
int deltaY = (int) (((float) (toY - fromY)) - prevTranslationY);
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, (float) (-deltaX));
ViewCompat.setTranslationY(newHolder.itemView, (float) (-deltaY));
ViewCompat.setAlpha(newHolder.itemView, 0.0f);
}
this.mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例5: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY,
int toX, int toY) {
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
endAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null && newHolder.itemView != null) {
// carry over translation values
endAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例6: 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);
endAnimation(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;
}
示例7: getDividerBound
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
Rect bounds = new Rect(0, 0, 0, 0);
int transitionX = (int) ViewCompat.getTranslationX(child);
int transitionY = (int) ViewCompat.getTranslationY(child);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
bounds.left = parent.getPaddingLeft() +
mMarginProvider.dividerLeftMargin(position, parent) + transitionX;
bounds.right = parent.getWidth() - parent.getPaddingRight() -
mMarginProvider.dividerRightMargin(position, parent) + transitionX;
int dividerSize = getDividerSize(position, parent);
if (mDividerType == DividerType.DRAWABLE) {
bounds.top = child.getBottom() + params.topMargin + transitionY;
bounds.bottom = bounds.top + dividerSize;
} else {
bounds.top = child.getBottom() + params.topMargin + dividerSize / 2 + transitionY;
bounds.bottom = bounds.top;
}
return bounds;
}
示例8: animateMove
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public boolean animateMove(ViewHolder holder, int fromX, int fromY, int toX, int toY) {
View view = holder.itemView;
fromX = (int) (((float) fromX) + ViewCompat.getTranslationX(holder.itemView));
fromY = (int) (((float) 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, (float) (-deltaX));
}
if (deltaY != 0) {
ViewCompat.setTranslationY(view, (float) (-deltaY));
}
this.mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
return true;
}
示例9: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) {
if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes.
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
// carry over translation values
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例10: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) {
if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes.
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// Recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
// Carry over translation values
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例11: 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));
}
}
示例12: 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);
}
}
示例13: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) {
if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes.
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
// carry over translation values
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例14: 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;
}
示例15: getSelectedDxDy
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void getSelectedDxDy(float[] outPosition) {
if ((mSelectedFlags & (LEFT | RIGHT)) != 0) {
outPosition[0] = mSelectedStartX + mDx - mSelected.itemView.getLeft();
} else {
outPosition[0] = ViewCompat.getTranslationX(mSelected.itemView);
}
if ((mSelectedFlags & (UP | DOWN)) != 0) {
outPosition[1] = mSelectedStartY + mDy - mSelected.itemView.getTop();
} else {
outPosition[1] = ViewCompat.getTranslationY(mSelected.itemView);
}
}