- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为我的初始屏幕制作翻转卡片动画。我已将屏幕垂直分成 3 个部分,并尝试将它们翻转为 Front - Back (Pause for a second) - Front
我发现了一个很好的问题here这帮助我弄清楚了 Front - Back 部分,但无论我做什么,我都无法将它们翻转回去。我是动画新手,所以请帮助我!谢谢!
FlipAnimation.java
public class FlipAnimation extends Animation {
private Camera camera;
private View fromView;
private View toView;
private float centerX;
private float centerY;
private boolean forward = true;
/**
* Creates a 3D flip animation between two views.
*
* @param fromView
* First view in the transition.
* @param toView
* Second view in the transition.
*/
public FlipAnimation(View fromView, View toView) {
this.fromView = fromView;
this.toView = toView;
setDuration(1500);
setFillAfter(false);
setInterpolator(new AccelerateDecelerateInterpolator());
}
public void reverse() {
forward = false;
View switchView = toView;
toView = fromView;
fromView = switchView;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
centerX = width / 2;
centerY = height / 2;
camera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
// Angle around the y-axis of the rotation at the given time
// calculated both in radians and degrees.
final double radians = Math.PI * interpolatedTime;
float degrees = (float) (180.0 * radians / Math.PI);
// Once we reach the midpoint in the animation, we need to hide the
// source view and show the destination view. We also need to change
// the angle by 180 degrees so that the destination does not come in
// flipped around
if (interpolatedTime >= 0.5f) {
degrees -= 180.f;
fromView.setVisibility(View.GONE);
toView.setVisibility(View.VISIBLE);
}
if (forward)
degrees = -degrees; // determines direction of rotation when flip
// begins
final Matrix matrix = t.getMatrix();
camera.save();
camera.translate(0, 0, Math.abs(degrees) * 2);
camera.getMatrix(matrix);
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
SplashActivity.java
public class SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
flipCard1();
flipCard2();
flipCard3();
flipBack1();
flipBack2();
flipBack3();
}
private void flipCard1() {
Log.i("Debug_Tag", "Inside flipCard1");
View rootLayout = (View) findViewById(R.id.main_activity_root1);
View cardFace1 = (View) findViewById(R.id.main_activity_card_face1);
View cardBack1 = (View) findViewById(R.id.main_activity_card_back1);
FlipAnimation flipAnimation1 = new FlipAnimation(cardFace1, cardBack1);
if (cardFace1.getVisibility() == View.GONE) {
flipAnimation1.reverse();
}
rootLayout.startAnimation(flipAnimation1);
}
private void flipCard2() {
View rootLayout = (View) findViewById(R.id.main_activity_root2);
View cardFace2 = (View) findViewById(R.id.main_activity_card_face2);
View cardBack2 = (View) findViewById(R.id.main_activity_card_back2);
FlipAnimation flipAnimation2 = new FlipAnimation(cardFace2, cardBack2);
if (cardFace2.getVisibility() == View.GONE) {
flipAnimation2.reverse();
}
rootLayout.startAnimation(flipAnimation2);
}
private void flipCard3() {
View rootLayout = (View) findViewById(R.id.main_activity_root3);
View cardFace3 = (View) findViewById(R.id.main_activity_card_face3);
View cardBack3 = (View) findViewById(R.id.main_activity_card_back3);
FlipAnimation flipAnimation3 = new FlipAnimation(cardFace3, cardBack3);
if (cardFace3.getVisibility() == View.GONE) {
flipAnimation3.reverse();
}
rootLayout.startAnimation(flipAnimation3);
}
private void flipBack1() {
View rootLayout = (View) findViewById(R.id.main_activity_root1);
View cardFace1 = (View) findViewById(R.id.main_activity_card_face1);
View cardBack1 = (View) findViewById(R.id.main_activity_card_back1);
FlipAnimation flipBackAnimation11 = new FlipAnimation(cardBack1,
cardFace1);
if (cardBack1.getVisibility() == View.GONE) {
flipBackAnimation11.reverse();
}
rootLayout.startAnimation(flipBackAnimation11);
}
private void flipBack2() {
View rootLayout = (View) findViewById(R.id.main_activity_root1);
View cardFace2 = (View) findViewById(R.id.main_activity_card_face2);
View cardBack2 = (View) findViewById(R.id.main_activity_card_back2);
FlipAnimation flipBackAnimation22 = new FlipAnimation(cardBack2,
cardFace2);
if (cardBack2.getVisibility() == View.GONE) {
flipBackAnimation22.reverse();
}
rootLayout.startAnimation(flipBackAnimation22);
}
private void flipBack3() {
View rootLayout = (View) findViewById(R.id.main_activity_root1);
View cardFace3 = (View) findViewById(R.id.main_activity_card_face3);
View cardBack3 = (View) findViewById(R.id.main_activity_card_back3);
FlipAnimation flipBackAnimation33 = new FlipAnimation(cardBack3,
cardFace3);
if (cardBack3.getVisibility() == View.GONE) {
flipBackAnimation33.reverse();
}
rootLayout.startAnimation(flipBackAnimation33);
}
}
splash.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_activity_rootMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >
<RelativeLayout
android:id="@+id/main_activity_root1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >
<RelativeLayout
android:id="@+id/main_activity_card_face1"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="@drawable/front"
android:clickable="true"
android:onClick="onCardClick"
android:padding="5dp" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_card_back1"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="@drawable/back"
android:clickable="true"
android:onClick="onCardClick"
android:visibility="gone" >
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_root2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >
<RelativeLayout
android:id="@+id/main_activity_card_face2"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/front"
android:clickable="true"
android:onClick="onCardClick"
android:padding="5dp" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_card_back2"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/back"
android:clickable="true"
android:onClick="onCardClick"
android:visibility="gone" >
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_root3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >
<RelativeLayout
android:id="@+id/main_activity_card_face3"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/front"
android:clickable="true"
android:onClick="onCardClick"
android:padding="5dp" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_card_back3"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/back"
android:clickable="true"
android:onClick="onCardClick"
android:visibility="gone" >
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
最佳答案
要在3.0以下平台实现翻转卡片动画,可以按如下方式实现:
在drawable文件夹中添加两个drawable
public class SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
flipCard(R.id.main_activity_root1, R.id.main_activity_card_face1,
R.id.main_activity_card_back1);
flipCard(R.id.main_activity_root2, R.id.main_activity_card_face2,
R.id.main_activity_card_back2);
flipCard(R.id.main_activity_root3, R.id.main_activity_card_face3,
R.id.main_activity_card_back3);
}
private void flipCard(int idRootLayout, int idCardFace, int idCardBack) {
final View rootLayout = (View) findViewById(idRootLayout);
final View cardFace = (View) findViewById(idCardFace);
final View cardBack = (View) findViewById(idCardBack);
FlipAnimation flipAnimation1 = new FlipAnimation(cardFace, cardBack);
AnimationListener flipAnimation1Listener = new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
cardBack.setVisibility(View.VISIBLE);
cardFace.setVisibility(View.VISIBLE);
FlipAnimation f = new FlipAnimation(cardFace, cardBack);
f.reverse();
rootLayout.startAnimation(f);
}
};
flipAnimation1.setAnimationListener(flipAnimation1Listener);
rootLayout.startAnimation(flipAnimation1);
}
}
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Transformation;
public class FlipAnimation extends Animation {
private Camera camera;
private View fromView;
private View toView;
private float centerX;
private float centerY;
private boolean forward = true;
public FlipAnimation(View fromView, View toView) {
this.fromView = fromView;
this.toView = toView;
setDuration(1500);
setFillAfter(false);
setInterpolator(new AccelerateDecelerateInterpolator());
}
public void reverse() {
forward = false;
View switchView = toView;
toView = fromView;
fromView = switchView;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
centerX = width / 2;
centerY = height / 2;
camera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final double radians = Math.PI * interpolatedTime;
float degrees = (float) (180.0 * radians / Math.PI);
if (interpolatedTime >= 0.5f) {
degrees -= 180.f;
fromView.setVisibility(View.GONE);
toView.setVisibility(View.VISIBLE);
}
if (forward)
degrees = -degrees;
final Matrix matrix = t.getMatrix();
camera.save();
camera.translate(0, 0, Math.abs(degrees) * 2);
camera.getMatrix(matrix);
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_activity_rootMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >
<RelativeLayout
android:id="@+id/main_activity_root1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >
<RelativeLayout
android:id="@+id/main_activity_card_face1"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="@drawable/front"
android:clickable="true"
android:onClick="onCardClick"
android:padding="5dp" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_card_back1"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="@drawable/back"
android:clickable="true"
android:onClick="onCardClick"
android:visibility="gone" >
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_root2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >
<RelativeLayout
android:id="@+id/main_activity_card_face2"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/front"
android:clickable="true"
android:onClick="onCardClick"
android:padding="5dp" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_card_back2"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/back"
android:clickable="true"
android:onClick="onCardClick"
android:visibility="gone" >
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_root3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >
<RelativeLayout
android:id="@+id/main_activity_card_face3"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/front"
android:clickable="true"
android:onClick="onCardClick"
android:padding="5dp" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_activity_card_back3"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/back"
android:clickable="true"
android:onClick="onCardClick"
android:visibility="gone" >
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
归因:XML 和动画 java 文件来自 the question
关于apis < 3.0 上的 android 翻转卡片动画不会向后翻转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20392292/
我有一个数据集,我试图在其中探索将变量限制在给定值并将超出的部分滚动到后续间隔的影响。我可以从概念上看到一些方法可以使用 cumsum() 来做到这一点。或类似的,但正在努力了解如何以合乎逻辑的方式实
我正在开发一个使用 iPhone 前置摄像头的应用程序。当使用该相机拍摄图像时,iPhone 会水平扭曲图像。我想将其镜像回来,以便能够保存它并按照在 iPhone 屏幕上看到的方式显示它。 我读了很
这是 HTML // stuff here Order /
我正在使用 Jquery - 是否有一种简单的方法可以在用户滑过 div 时更改它的背景颜色? 最佳答案 你可以用 CSS 做到这一点: #myDiv:hover { background-color
有谁知道是否可以翻转图像并在其背面显示内容。这就是我的意思:想象一下你手里拿着一张肖像。然后你翻转并查看肖像的背面,背面有文字。我正在寻找类似的东西,单击图像将镜像/翻转到另一侧,上面有文字。不可90
我在翻车方面遇到了一些麻烦..希望你能帮助我! 我正在使用 li 导航,我希望有单独的框链接到不同的页面。这部分很好,可以正常工作。我希望能够将鼠标悬停在框上并让框和链接改变颜色。我可以毫无问题地改变
所以我目前在 Vuejs 中有一个组件,用户可以在其中从他们的本地文件系统中选择一个文件。用户选择图片后,图片会在 div 中预览 codesandbox .出于某种原因,某些图像会自动“翻转”到侧面
我有一个滚动顶部菜单。我正在尝试获取它,以便我的背景图像 (17px x 13px) 悬停在中央。我已经尝试了所有背景 css 属性,但似乎没有任何效果。我是不是用错了方法? 这是我的 CSS: #n
我以前用过这个效果,一切正常(据我所知),但就是不行。我错过了什么? Fiddle here Sprite here 谢谢。 最佳答案 由于您的 Sprite 是水平排列的,因此您需要像这样偏移悬停状
代码后面的代码不起作用,因为重新查找接受字符串作为第一个参数,正则表达式作为第二个参数。 (-> "hello" .toUpperCase (re-find #".$")) 如果我像这
我想使用 CABasicAnimation 翻转 UILabel。动画将永远重复,并将在两个不同值之间更改 UILabel 的文本。 - (void)animateLabel { [self
旋转 WPF 图像非常简单 imgCurrent.LayoutTransform = new RotateTransform(_rotationAngle); 水平和垂直镜像呢? 机外: In GDI
我需要创建一个动画 - 翻转一个 View 并显示另一个。 当前显示的 View 的宽度慢慢减小到零,之后要显示的 View 的宽度必须从零开始增加。 在此期间,高度从当前显示的高度变为略微降低的高度
我正在尝试找到翻转 Rust 中 boolean 值的最快方法?即 false => true true => false 对于我的应用程序,我不关心 boolean 值的当前值,只关心它被翻转了。对
是否可以翻转 primefaces 中的数据表,以使标题位于左侧而不是顶部?我有下表: 如您所见
我在翻转 View 时遇到了一些问题。我的 View Controller 中有以下代码: - (void)loadFlipsideViewController { ProblemViewFl
我正在使用翻转动画在 View Controller 中的两个 View 之间制作动画。问题是动画发生时背景显示白色空白背景。我想显示黑色背景。 我尝试在 IB 和代码中将主视图的背景颜色设置为黑色。
请考虑下面的代码,并告诉我我做错了什么。 我想在两个 UIView 之间切换。 不知何故,当我从初始 View 翻转时,我只是得到翻转的 View ,没有动画。当我向后翻转时,动画显示得很好。 翻转是
我有一个 NSScrollView,需要在其中显示可变数量的 NSView。我制作了一个自定义 NSView,它的 isFlipped 返回 YES 并将我的 NSView 放入其中,然后将其设置为
我有一个 NSView 的子类,它重新实现了许多鼠标事件函数。例如,在 mouseDown 中从我使用的 NSEvent 获取点: NSEvent *theEvent; // <- argument
我是一名优秀的程序员,十分优秀!