下面列出了android.view.View#setRotationX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)}.
* <p>
* The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
* not modify the same page properties. For instance changing from a transformation that applies rotation to a
* transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
* alpha.
*
* @param page
* Apply the transformation to this page
* @param position
* Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
protected void onPreTransform(View page, float position) {
final float width = page.getWidth();
page.setRotationX(0);
page.setRotationY(0);
page.setRotation(0);
page.setScaleX(1);
page.setScaleY(1);
page.setPivotX(0);
page.setPivotY(0);
page.setTranslationY(0);
page.setTranslationX(isPagingEnabled() ? 0f : -width * position);
if (hideOffscreenPages()) {
page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
page.setEnabled(false);
} else {
page.setEnabled(true);
page.setAlpha(1f);
}
}
/**
* Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)}.
* <p>
* The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
* not modify the same page properties. For instance changing from a transformation that applies rotation to a
* transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
* alpha.
*
* @param page
* Apply the transformation to this page
* @param position
* Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
protected void onPreTransform(View page, float position) {
final float width = page.getWidth();
page.setRotationX(0);
page.setRotationY(0);
page.setRotation(0);
page.setScaleX(1);
page.setScaleY(1);
page.setPivotX(0);
page.setPivotY(0);
page.setTranslationY(0);
page.setTranslationX(isPagingEnabled() ? 0f : -width * position);
if (hideOffscreenPages()) {
page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
page.setEnabled(false);
} else {
page.setEnabled(true);
page.setAlpha(1f);
}
}
@Override
public Animator getInAnimator(View target, SlideShowView parent, int fromSlide, int toSlide) {
target.setAlpha(0);
target.setScaleX(SCALE_FACTOR);
target.setScaleY(SCALE_FACTOR);
target.setTranslationX(0);
target.setTranslationY(0);
target.setRotationX(0);
target.setRotationY(0);
final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat(View.ALPHA, 1);
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, scaleX, scaleY, alpha);
animator.setDuration(getDuration());
animator.setInterpolator(getInterpolator());
return animator;
}
/**
* Lifting view
*
* @param view The animation target
* @param baseRotation initial Rotation X in 3D space
* @param duration aniamtion duration
* @param startDelay start delay before animation begin
*/
@Deprecated
public static void liftingFromBottom(View view, float baseRotation, int duration, int startDelay){
view.setRotationX(baseRotation);
view.setTranslationY(view.getHeight() / 3);
view
.animate()
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(duration)
.setStartDelay(startDelay)
.rotationX(0)
.translationY(0)
.start();
}
protected void onPreTransform(View page, float position) {
final float width = page.getWidth();
page.setRotationX(0);
page.setRotationY(0);
page.setRotation(0);
page.setScaleX(1);
page.setScaleY(1);
page.setPivotX(0);
page.setPivotY(0);
page.setTranslationY(0);
page.setTranslationX(isPagingEnabled() ? 0f : -width * position);
if (hideOffscreenPages()) {
page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
} else {
page.setAlpha(1f);
}
}
@Override
protected void onTransform(View view, float position, boolean forwardDirection, int mOrientation) {
final float rotation = (position < 0 ? 30f : -30f) * Math.abs(position);
if (mOrientation == OnPageDataListener.HORIZONTAL) {
view.setTranslationX(getOffsetForRotation(rotation, view.getWidth(), view.getHeight(), mOrientation));
view.setPivotX(view.getWidth() * 0.5f);
view.setPivotY(0);
view.setRotationY(rotation);
} else {
view.setTranslationY(getOffsetForRotation(rotation, view.getWidth(), view.getHeight(), mOrientation));
view.setPivotY(view.getHeight() * 0.5f);
view.setPivotX(0);
view.setRotationX(-rotation);
}
}
protected void setItemViewProperty(View itemView, float targetOffset) {
float scale = calculateScale(targetOffset + mSpaceMain);
itemView.setScaleX(scale);
itemView.setScaleY(scale);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
itemView.setElevation(0);
}
final float rotation = calRotation(targetOffset);
if (getOrientation() == HORIZONTAL) {
itemView.setRotationY(rotation);
} else {
itemView.setRotationX(-rotation);
}
}
public static void clearAnimation(View view) {
view.setAlpha(1);
view.setScaleX(1);
view.setScaleY(1);
view.setTranslationX(0);
view.setTranslationY(0);
view.setRotation(0);
view.setRotationX(0);
view.setRotationY(0);
}
private void resetAnimatedView(View child) {
child.setAlpha(1.f);
child.setTranslationX(0.f);
child.setTranslationY(0.f);
child.setRotation(0.f);
child.setRotationY(0.f);
child.setRotationX(0.f);
child.setScaleX(1.f);
child.setScaleY(1.f);
}
@Override
protected void onTransform(View view, float position) {
final float rotation = -180f * position;
view.setAlpha(rotation > 90f || rotation < -90f ? 0f : 1f);
view.setPivotX(view.getWidth() * 0.5f);
view.setPivotY(view.getHeight() * 0.5f);
view.setRotationX(rotation);
}
@Override
public void setRotationX(float rotationX) {
View targetView;
if ((targetView = getTargetView()) != null){
targetView.setRotationX(rotationX);
}
}
public static void clear(View v) {
v.setAlpha(1);
v.setScaleY(1);
v.setScaleX(1);
v.setTranslationY(0);
v.setTranslationX(0);
v.setRotation(0);
v.setRotationY(0);
v.setRotationX(0);
v.setPivotY(v.getMeasuredHeight() / 2);
v.setPivotX(v.getMeasuredWidth() / 2);
ViewCompat.animate(v).setInterpolator(null).setStartDelay(0);
}
@Override
protected void onTransform(View view, float position) {
final float rotation = -180f * position;
view.setAlpha(rotation > 90f || rotation < -90f ? 0f : 1f);
view.setPivotX(view.getWidth() * 0.5f);
view.setPivotY(view.getHeight() * 0.5f);
view.setRotationX(rotation);
}
public static void reset(View view) {
view.setAlpha(1);
view.setScaleX(1);
view.setScaleY(1);
view.setTranslationX(0);
view.setTranslationY(0);
view.setRotation(0);
view.setRotationY(0);
view.setRotationX(0);
}
@Override
public void setValue(View view, float value) {
view.setRotationX(value);
}
public static void setRotationX(View view, float value) {
view.setRotationX(value);
}
static void setRotationX(View view, float rotationX) {
view.setRotationX(rotationX);
}
static void e(View view, float f1)
{
view.setRotationX(f1);
}
static void setRotationX(View view, float rotationX) {
view.setRotationX(rotationX);
}
static void setRotationX(View view, float rotationX) {
view.setRotationX(rotationX);
}