- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用消息传递应用程序,我想将新用户显示为动画飞行图标,如 facebook 实时 float react 。任何人都可以启发我应该遵循哪个过程或任何有用的图书馆链接吗?
我已经尝试浏览并检查了几个库链接,例如 this1和 this2但这些与 facebook 实时 react 包不同。
最佳答案
我通过修改旧代码实现了这一点所以这是我的解决方案。您可以更改表情符号的方向和数量,也可以让它在任何 View 上方或下方飞行。
主要 xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top|left"
android:orientation="vertical">
<FrameLayout
android:id="@+id/animation_holder"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
主要 Activity
package com.example.hamidraza.flyinemojis;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.animation.Animation;
public class MainActivity extends Activity {
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.activity_main);
emoji_one();
emoji_two();
emoji_three();
}
public void flyEmoji(final int resId) {
ZeroGravityAnimation animation = new ZeroGravityAnimation();
animation.setCount(1);
animation.setScalingFactor(0.2f);
animation.setOriginationDirection(Direction.BOTTOM);
animation.setDestinationDirection(Direction.TOP);
animation.setImage(resId);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}
);
ViewGroup container = findViewById(R.id.animation_holder);
animation.play(this,container);
}
public void emoji_one() {
// You can change the number of emojis that will be flying on screen
for (int i = 0; i < 5; i++) {
flyEmoji(R.drawable.emojis1);
}
}
// You can change the number of emojis that will be flying on screen
public void emoji_two(){
for(int i=0;i<5;i++) {
flyEmoji(R.drawable.dabemoji);
}
}
// You can change the number of emojis that will be flying on screen
public void emoji_three(){
for(int i=0;i<5;i++) {
flyEmoji(R.drawable.heart);
}
}
// This method will be used if You want to fly your Emois Over any view
// public void flyObject(final int resId, final int duration, final Direction from, final Direction to, final float scale) {
//
// ZeroGravityAnimation animation = new ZeroGravityAnimation();
// animation.setCount(1);
// animation.setScalingFactor(scale);
// animation.setOriginationDirection(from);
// animation.setDestinationDirection(to);
// animation.setImage(resId);
// animation.setDuration(duration);
// animation.setAnimationListener(new Animation.AnimationListener() {
// @Override
// public void onAnimationStart(Animation animation) {
//
// }
//
// @Override
// public void onAnimationEnd(Animation animation) {
//
// flyObject(resId, duration, from, to, scale);
// }
//
// @Override
// public void onAnimationRepeat(Animation animation) {
//
// }
// });
//
// ViewGroup container = (ViewGroup) findViewById(R.id.animation_bigger_objects_holder);
// animation.play(this,container);
//
// }
//
}
零重力动画
package com.example.hamidraza.flyinemojis;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
public class ZeroGravityAnimation {
private static final int RANDOM_DURATION = -1;
private Direction mOriginationDirection = Direction.RANDOM;
private Direction mDestinationDirection = Direction.RANDOM;
private int mDuration = RANDOM_DURATION;
private int mCount = 1;
private int mImageResId;
private float mScalingFactor = 1f;
private Animation.AnimationListener mAnimationListener;
/**
* Sets the orignal direction. The animation will originate from the given direction.
*/
public ZeroGravityAnimation setOriginationDirection(Direction direction) {
this.mOriginationDirection = direction;
return this;
}
/**
* Sets the animation destination direction. The translate animation will proceed towards the given direction.
* @param direction
* @return
*/
public ZeroGravityAnimation setDestinationDirection(Direction direction) {
this.mDestinationDirection = direction;
return this;
}
/**
* Will take a random time duriation for the animation
* @return
*/
public ZeroGravityAnimation setRandomDuration() {
return setDuration(RANDOM_DURATION);
}
/**
* Sets the time duration in millseconds for animation to proceed.
* @param duration
* @return
*/
public ZeroGravityAnimation setDuration(int duration) {
this.mDuration = duration;
return this;
}
/**
* Sets the image reference id for drawing the image
* @param resId
* @return
*/
public ZeroGravityAnimation setImage(int resId) {
this.mImageResId = resId;
return this;
}
/**
* Sets the image scaling value.
* @param scale
* @return
*/
public ZeroGravityAnimation setScalingFactor(float scale) {
this.mScalingFactor = scale;
return this;
}
public ZeroGravityAnimation setAnimationListener(Animation.AnimationListener listener) {
this.mAnimationListener = listener;
return this;
}
public ZeroGravityAnimation setCount(int count) {
this.mCount = count;
return this;
}
/**
* Starts the Zero gravity animation by creating an OTT and attach it to th given ViewGroup
* @param activity
* @param ottParent
*/
public void play(Activity activity, ViewGroup ottParent) {
DirectionGenerator generator = new DirectionGenerator();
if(mCount > 0) {
for (int i = 0; i < mCount; i++) {
final int iDupe = i;
Direction origin = mOriginationDirection == Direction.RANDOM ? generator.getRandomDirection() : mOriginationDirection;
Direction destination = mDestinationDirection == Direction.RANDOM ? generator.getRandomDirection(origin) : mDestinationDirection;
int startingPoints[] = generator.getPointsInDirection(activity, origin);
int endPoints[] = generator.getPointsInDirection(activity,destination);
Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(), mImageResId);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth() * mScalingFactor), (int) (bitmap.getHeight() * mScalingFactor), false);
switch (origin) {
case LEFT:
startingPoints[0] -= scaledBitmap.getWidth();
break;
case RIGHT:
startingPoints[0] += scaledBitmap.getWidth();
break;
case TOP:
startingPoints[1] -= scaledBitmap.getHeight();
break;
case BOTTOM:
startingPoints[1] += scaledBitmap.getHeight();
break;
}
switch (destination) {
case LEFT:
endPoints[0] -= scaledBitmap.getWidth();
break;
case RIGHT:
endPoints[0] += scaledBitmap.getWidth();
break;
case TOP:
endPoints[1] -= scaledBitmap.getHeight();
break;
case BOTTOM:
endPoints[1] += scaledBitmap.getHeight();
break;
}
final OverTheTopLayer layer = new OverTheTopLayer();
FrameLayout ottLayout = layer.with(activity)
.scale(mScalingFactor)
.attachTo(ottParent)
.setBitmap(scaledBitmap, startingPoints)
.create();
switch (origin) {
case LEFT:
}
int deltaX = endPoints[0] - startingPoints[0];
int deltaY = endPoints[1] - startingPoints[1];
int duration = mDuration;
if (duration == RANDOM_DURATION) {
duration = RandomUtil.generateRandomBetween(3500, 12500);
}
TranslateAnimation animation = new TranslateAnimation(0, deltaX, 0, deltaY);
animation.setDuration(duration);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
if (iDupe == 0) {
if (mAnimationListener != null) {
mAnimationListener.onAnimationStart(animation);
}
}
}
@Override
public void onAnimationEnd(Animation animation) {
layer.destroy();
if (iDupe == (mCount - 1)) {
if (mAnimationListener != null) {
mAnimationListener.onAnimationEnd(animation);
}
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
layer.applyAnimation(animation);
}
}
else {
Log.e(ZeroGravityAnimation.class.getSimpleName(),"Count was not provided, animation was not started");
}
}
/**
* Takes the content view as view parent for laying the animation objects and starts the animation.
* @param activity - activity on which the zero gravity animation should take place.
*/
public void play(Activity activity) {
play(activity,null);
}
}
RandomUtils java 类
package com.example.hamidraza.flyinemojis;
import java.util.Random;
public class RandomUtil {
/**
* Generates the random between two given integers.
*/
public static int generateRandomBetween(int start, int end) {
Random random = new Random();
int rand = random.nextInt(Integer.MAX_VALUE - 1) % end;
if (rand < start) {
rand = start;
}
return rand;
}
}
方向
package com.example.hamidraza.flyinemojis;
public enum Direction {
TOP, LEFT, RIGHT, BOTTOM,RANDOM
}
方向发生器
package com.example.hamidraza.flyinemojis;
import android.app.Activity;
import java.util.Random;
public class DirectionGenerator {
/**
* Gets the random pixel points in the given direction of the screen
* @param activity - activity from where you are referring the random value.
* @param direction - on among LEFT,RIGHT,TOP,BOTTOM,RANDOM
* @return a pixel point {x,y} in the given direction.
*/
public int[] getPointsInDirection(Activity activity, Direction direction) {
switch (direction) {
case LEFT:
return getRandomLeft(activity);
case RIGHT:
return getRandomRight(activity);
case BOTTOM:
return getRandomBottom(activity);
case TOP:
return getRandomTop(activity);
default:
Direction[] allDirections = new Direction[]{Direction.LEFT,Direction.TOP,Direction.BOTTOM,Direction.RIGHT};
int index = new Random().nextInt(allDirections.length);
return getPointsInDirection(activity, allDirections[index]);
}
}
/**
* Gets the random pixel points in the left direction of the screen. The value will be of {0,y} where y will be a random value.
* @param activity - activity from where you are referring the random value.
* @return a pixel point {x,y}.
*/
public int[] getRandomLeft(Activity activity) {
int x = 0;
int height = activity.getResources().getDisplayMetrics().heightPixels;
Random random = new Random();
int y = random.nextInt(height);
return new int[]{x, y};
}
/**
* Gets the random pixel points in the top direction of the screen. The value will be of {x,0} where x will be a random value.
* @param activity - activity from where you are referring the random value.
* @return a pixel point {x,y}.
*/
public int[] getRandomTop(Activity activity) {
int y = 0;
int width = activity.getResources().getDisplayMetrics().widthPixels;
Random random = new Random();
int x = random.nextInt(width);
return new int[]{x, y};
}
/**
* Gets the random pixel points in the right direction of the screen. The value will be of {screen_width,y} where y will be a random value.
* @param activity - activity from where you are referring the random value.
* @return a pixel point {x,y}.
*/
public int[] getRandomRight(Activity activity) {
int width = activity.getResources().getDisplayMetrics().widthPixels;
int height = activity.getResources().getDisplayMetrics().heightPixels;
int x = width ;
Random random = new Random();
int y = random.nextInt(height);
return new int[]{x, y};
}
/**
* Gets the random pixel points in the bottom direction of the screen. The value will be of {x,screen_height} where x will be a random value.
* @param activity - activity from where you are referring the random value.
* @return a pixel point {x,y}.
*/
public int[] getRandomBottom(Activity activity) {
int width = activity.getResources().getDisplayMetrics().widthPixels;
int height = activity.getResources().getDisplayMetrics().heightPixels;
int y = height ;
Random random = new Random();
int x = random.nextInt(width);
return new int[]{x, y};
}
/**
* Gets a random direction.
* @return one among LEFT,RIGHT,BOTTOM,TOP
*/
public Direction getRandomDirection() {
Direction[] allDirections = new Direction[]{Direction.LEFT,Direction.TOP,Direction.BOTTOM,Direction.RIGHT};
int index = new Random().nextInt(allDirections.length);
return (allDirections[index]);
}
/**
* Gets a random direction skipping the given direction.
* @param toSkip a direction which should not be returned by this method.
* @return one among LEFT,RIGHT,BOTTOM if TOP is provided as direction to skip,
* one among TOP,RIGHT,BOTTOM if LEFT is provided as direction to skip
* and so on.
*/
public Direction getRandomDirection(Direction toSkip) {
Direction[] allExceptionalDirections;
switch (toSkip) {
case LEFT:
allExceptionalDirections = new Direction[]{Direction.TOP,Direction.BOTTOM,Direction.RIGHT};
break;
case RIGHT:
allExceptionalDirections = new Direction[]{Direction.TOP,Direction.BOTTOM,Direction.LEFT};
break;
case BOTTOM:
allExceptionalDirections = new Direction[]{Direction.TOP,Direction.LEFT,Direction.RIGHT};
break;
case TOP:
allExceptionalDirections = new Direction[]{Direction.LEFT,Direction.BOTTOM,Direction.RIGHT};
break;
default:
allExceptionalDirections = new Direction[]{Direction.LEFT,Direction.TOP,Direction.BOTTOM,Direction.RIGHT};
}
int index = new Random().nextInt(allExceptionalDirections.length);
return (allExceptionalDirections[index]);
}
}
OverTheTopLayer
package com.example.hamidraza.flyinemojis;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import java.lang.ref.WeakReference;
public class OverTheTopLayer {
public static class OverTheTopLayerException extends RuntimeException {
public OverTheTopLayerException(String msg) {
super(msg);
}
}
private WeakReference<Activity> mWeakActivity;
private WeakReference<ViewGroup> mWeakRootView;
private FrameLayout mCreatedOttLayer;
private float mScalingFactor = 1.0f;
private int[] mDrawLocation = {0, 0};
private Bitmap mBitmap;
public OverTheTopLayer() {
}
/**
* To create a layer on the top of activity
*/
public OverTheTopLayer with(Activity weakReferenceActivity) {
mWeakActivity = new WeakReference<Activity>(weakReferenceActivity);
return this;
}
/**
* Draws the image as per the drawable resource id on the given location pixels.
*/
public OverTheTopLayer generateBitmap(Resources resources, int drawableResId, float mScalingFactor, int[] location) {
if (location == null) {
location = new int[]{0, 0};
} else if (location.length != 2) {
throw new OverTheTopLayerException("Requires location as an array of length 2 - [x,y]");
}
Bitmap bitmap = BitmapFactory.decodeResource(resources, drawableResId);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth() * mScalingFactor), (int) (bitmap.getHeight() * mScalingFactor), false);
this.mBitmap = scaledBitmap;
this.mDrawLocation = location;
return this;
}
public OverTheTopLayer setBitmap(Bitmap bitmap, int[] location) {
if (location == null) {
location = new int[]{0, 0};
} else if (location.length != 2) {
throw new OverTheTopLayerException("Requires location as an array of length 2 - [x,y]");
}
this.mBitmap = bitmap;
this.mDrawLocation = location;
return this;
}
/**
* Holds the scaling factor for the image.
*
* @param scale
* @return
*/
public OverTheTopLayer scale(float scale) {
if (scale <= 0) {
throw new OverTheTopLayerException("Scaling should be > 0");
}
this.mScalingFactor = scale;
return this;
}
/**
* Attach the OTT layer as the child of the given root view.
* @return
*/
public OverTheTopLayer attachTo(ViewGroup rootView) {
this.mWeakRootView = new WeakReference<ViewGroup>(rootView);
return this;
}
/**
* Creates an OTT.
* @return
*/
public FrameLayout create() {
if(mCreatedOttLayer != null) {
destroy();
}
if (mWeakActivity == null) {
throw new OverTheTopLayerException("Could not create the layer as not activity reference was provided.");
}
Activity activity = mWeakActivity.get();
if (activity != null) {
ViewGroup attachingView = null;
if (mWeakRootView != null && mWeakRootView.get() != null) {
attachingView = mWeakRootView.get();
} else {
attachingView = (ViewGroup) activity.findViewById(android.R.id.content);
}
ImageView imageView = new ImageView(activity);
imageView.setImageBitmap(mBitmap);
int minWidth = mBitmap.getWidth();
int minHeight = mBitmap.getHeight();
imageView.measure(View.MeasureSpec.makeMeasureSpec(minWidth, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(minHeight, View.MeasureSpec.AT_MOST));
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
if (params == null) {
params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.TOP);
imageView.setLayoutParams(params);
}
int xPosition = mDrawLocation[0];
int yPosition = mDrawLocation[1];
params.width = minWidth;
params.height = minHeight;
params.leftMargin = xPosition;
params.topMargin = yPosition;
imageView.setLayoutParams(params);
FrameLayout ottLayer = new FrameLayout(activity);
FrameLayout.LayoutParams topLayerParam = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT, Gravity.TOP);
ottLayer.setLayoutParams(topLayerParam);
ottLayer.addView(imageView);
attachingView.addView(ottLayer);
mCreatedOttLayer = ottLayer;
} else {
Log.e(OverTheTopLayer.class.getSimpleName(), "Could not create the layer. Reference to the activity was lost");
}
return mCreatedOttLayer;
}
/**
* Kills the OTT
*/
public void destroy() {
if (mWeakActivity == null) {
throw new OverTheTopLayerException("Could not create the layer as not activity reference was provided.");
}
Activity activity = mWeakActivity.get();
if (activity != null) {
ViewGroup attachingView = null;
if (mWeakRootView != null && mWeakRootView.get() != null) {
attachingView = mWeakRootView.get();
} else {
attachingView = (ViewGroup) activity.findViewById(android.R.id.content);
}
if (mCreatedOttLayer != null) {
attachingView.removeView(mCreatedOttLayer);
mCreatedOttLayer = null;
}
} else {
Log.e(OverTheTopLayer.class.getSimpleName(), "Could not destroy the layer as the layer was never created.");
}
}
/**
* Applies the animation to the image view present in OTT.
* @param animation
*/
public void applyAnimation(Animation animation) {
if(mCreatedOttLayer != null) {
ImageView drawnImageView = (ImageView) mCreatedOttLayer.getChildAt(0);
drawnImageView.startAnimation(animation);
}
}
}
关于android - 创建 Facebook 实时 react 动画叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45712573/
我为我们的业务创建了一个 Facebook 页面,我创建了一个 Facebook 应用程序来获取 AppID,以便在 Facebook 插件中使用它。 我注意到 Facebook 应用程序的页面看起来
是否有可能知道哪个 Facebook 用户点击了我的应用用户在 Facebook 上分享的链接? 为了清楚起见,让我改写一下:我想知道我的应用用户的哪些 friend 点击了他的共享链接。 感谢任何提
我正在浏览 facebook pixel,对 facebook pixel 如何知道哪个转化来自哪个 facebook 广告感到很困惑? 假设我有这个 url http://example.com安装
我正在开发 sucsongmoi.net(越南语),当浏览者从他们的墙上分享网站链接时,一些链接 facebook 获得描述和图像,一些链接 facebook 无法获得描述和图像。 例如:分享 suc
一位同事错误地设置了个人 Facebook 页面;它应该是一个企业 Facebook 页面。 个人页面上有几个 friend 需要重定向到正确的 Facebook 业务页面。 我可以将用户从错误的个人
在 Facebook 上,当您转到“编辑我的个人资料”>“艺术和娱乐”时,会有一个“电影”自动完成小部件,它会在您输入电影时推荐电影。 因此,如果您输入“Jones”,它将开始建议: 印第安纳琼斯 布
我在我的网页上使用 Facebook 登录。首次登录时,Facebook 登录应用程序会请求获取用户数据的权限。 有什么方法可以改善这个问题,以请求喜欢我的 Facebook 页面的许可?用户点击后,
我需要知道是否可以将现有的 Facebook 页面(类别:应用程序页面)链接到 Facebook 应用程序?当我进入 Facebook 应用程序设置时,他们建议创建一个新页面。但我需要的只是链接到现有
我的网站应用程序具有通过 Facebook 登录进行登录的功能。为此,我的应用程序出现在 Facebook 上。使用 Facebook 登录工作正常。 但应用程序具有将 Facebook 帐户链接和取
我正在制作一个应用程序,让人们可以在 Facebook 上与特定的 friend 分享内容。示例:Alice 使用我的应用程序,她与 Bob 分享了一篇文章,Bob 是她的 Facebook 好友。现
我正在按照列出的说明进行操作 http://docs.appcelerator.com/platform/latest/#!/api/Modules.Facebook 并查看 Arrow 示例目录中的
假设我有一个餐厅的商业网站,一位顾客为一大群人预订了一张 table 。有没有一种方法可以让客户有机会在餐厅网站上创建 Facebook 事件,作为预订流程的一部分。我知道客户必须以某种方式从餐厅网站
我想让我的用户将他们的用户帐户与 Facebook 或 Twitter 相关联,并允许他们使用他们的 Facebook/Twitter 帐户登录我的服务器,而不是使用传统的用户名/密码。与StackO
我们有一个面子书页面。我们添加了一个自定义 FBML 选项卡。现在我们要添加评论面子书插件。我尝试添加一个脚本,我从 Face book Social Plug in .代码是 之后我将此脚本放入自
大家好 请帮我找到关于以下的官方信息: 1) 什么是“FaceBook 登录” 2) 什么是“FaceBook Connect” 谢谢 最佳答案 你可以在那里找到你需要的一切: http://deve
这是最奇怪的事情。我有非常简单的 CF 代码,查看 cgi.HTTP_REFERER。简单地说,它查看推荐人。如果链接是从我们的主要网站域之外单击的,它会显示一些内容。否则,什么也不会发生。所以,如果
我还是 Facebook Graph API 的新手,正在尝试开始使用 Facebook 地点搜索。 (按位置搜索地点) https://graph.facebook.com/search?type=
我不想开设 Facebook 帐户,但我被要求为需要使用 Facebook API 的应用程序开发功能。有没有一种方法可以开发这些功能并使用 Facebook API,而无需开设个人 Facebook
我已经按照指示实现了 DotNetOpenAuth 提供的示例应用程序 here . 正如您在下面看到的,这要求用户安装此 facebook 应用程序。 我只是想让用户使用他们的 Facebook 登
我的主页上有标准的 Facebook 登录按钮,我不希望人们仅在用户单击登录按钮时使用他们的 Facebook 帐户自动登录我的网站。 如果用户未登录 Facebook,将出现一个弹出窗口询问他的凭据
我是一名优秀的程序员,十分优秀!