标签: android-animation

如何从xml文件加载AnimationDrawable

我有一些自定义类BitmapStorage,没有附加到任何View或其他任何东西 - 一个实用程序.我有born_animation.xml文件,其中包含带有动画帧的<animation-list>:

<animation-list oneshot="true" >
    <item drawable="@drawable/frame01" />
    <item drawable="@drawable/frame02" />
</animation-list>
Run Code Online (Sandbox Code Playgroud)

我想使用Resources类将动画从xml文件加载为AnimationDrawable(因此它会对我进行所有解析),提取位图并将它们放到我的自定义存储类中.

我有的问题是:

Resources res = context.getResources(); 
AnimationDrawable drawable = (AnimationDrawable)res.getDrawable(R.drawable.born_animation); 
assertTrue( drawable != null ); <= fails! it's null 
Run Code Online (Sandbox Code Playgroud)

WTF?有人可以解释一下吗?代码编译好.所有资源都已到位.

我尝试了另一种方法 - 使用ImageView进行解析(如开发指南中所述)

ImageView view = new ImageView(context); 
view.setBackgroundResource(R.drawable.born_animation); 
AnimationDrawable drawable = (AnimationDrawable)view.getBackground(); 
assertTrue( drawable != null ); <= fails! it's null 
Run Code Online (Sandbox Code Playgroud)

结果是一样的.它返回null drawable.

任何希望都会受到高度赞赏,提前谢谢.

android android-animation

15
推荐指数
2
解决办法
5万
查看次数

Android动画库?

我们可以在我们的应用程序中使用任何免费的Android动画库吗?

android内置动画非常基本.我想要一些更有趣的东西.

-

提前致谢.

android android-animation android-library

15
推荐指数
3
解决办法
2万
查看次数

Android:完成动画后,旋转动画会恢复到真实状态吗?

我要在我的应用程序中旋转图像.旋转时所有工作都很好.但是当我旋转动画完成时,Image将返回其先前的位置.我想要的是将图像保持为旋转状态而不是让它恢复到真实状态.

那么如何才能实现呢?要旋转图像,我使用下面的代码:

    <?xml version="1.0" encoding="utf-8"?>

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:fromDegrees="0"
    android:toDegrees="30"
    android:duration="2000">

</rotate>
Run Code Online (Sandbox Code Playgroud)

并将其应用于ImgeView,如:

myImageView.startAnimation(rotateRight);
Run Code Online (Sandbox Code Playgroud)

所以,请帮我解决这个问题.

animation android android-animation android-layout

15
推荐指数
1
解决办法
9833
查看次数

动画中的延迟(TranslateAnimation)

有没有办法Animation暂停半秒?

我正在尝试使用TranslateAnimationAPI 制作无限动画.所以,我使用RepeatCountas Infinite.我还注意到,有一种setStartOffset(...)方法可以涵盖我想要延迟启动动画的情况.但是,我无法在每次"重启"之前找到延迟的方法.由于动画会发生无限次,每次动画重新启动时我都需要延迟.

有任何想法吗?

谢谢!!

android android-animation translate-animation

15
推荐指数
2
解决办法
3万
查看次数

最有效的方式来逐帧动画显示android

我试图通过在imageview中更改图像来逐帧动画显示.我尝试在xml中绘制动画,并在Handler中更改imageview的位图.我还试图在arraylist中存储三个位图(以避免内存不足)作为缓存机制,但实际上是很低的改进.我需要迭代36张图像以获得完整的动画效果.我面临的问题是,在我使用的所有方法中,我无法在50ms的给定时间范围内完成动画.图像范围从最小250 kb到最大540 kb.动画的fps非常低.随着应用程序的ios版本准备就绪,我被限制为显示与ios版本一致的动画.我是renderscript和opengl的菜鸟.有没有办法在50-60ms内显示大图像的平滑动画.任何提示或建议都非常感谢.下面是动画的快照:这是任何一个感兴趣的人的图像链接. 在此输入图像描述

android android-animation

15
推荐指数
2
解决办法
6493
查看次数

Android - 使用AnimatorSet缩放动画

官方缩放视图教程使用a AnimatorSet来放大View.随着视野的扩大,它会产生向下运动的错觉.之后,AnimatorSet只是向后重放以创建缩小的幻觉.

放大向下移动 我需要实现的是与此完全相反的.我需要从扩展视图开始,然后将其缩小为一个向上移动的较小视图:

向上移动缩小 我似乎不能在示例中使用反转代码.该示例假定您首先放大视图并展开它,然后将其缩小回原始缩略图图标.

这是我到目前为止所尝试的内容.我的XML布局是

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#1999da">             

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:gravity="center">

        <!-- The final shrunk image -->

        <ImageView
            android:id="@+id/thumb_button_1"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_marginRight="1dp"
            android:visibility="invisible"/>

    </LinearLayout>

</LinearLayout>

<!-- The initial expanded image that needs to be shrunk -->

<ImageView
    android:id="@+id/expanded_image"
    android:layout_width="wrap_content"
    android:layout_height="125dp"
    android:layout_gravity="center"
    android:src="@drawable/title_logo_expanded"
    android:scaleType="centerCrop"/>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这是执行缩小操作的方法.我基本上试图颠倒教程中的过程:

private void zoomImageFromThumbReverse(final View expandedImageView, int imageResId, final int duration) {
    // If there's an animation in …
Run Code Online (Sandbox Code Playgroud)

java android android-animation objectanimator viewpropertyanimator

15
推荐指数
1
解决办法
2926
查看次数

Android动画翻盖和缓解(打开书本动画)

那里有几个按钮/图像.点击我想要这样的动画:

(图像打开)书籍封面打开,相关的活动/片段在动画中轻松打开,全屏.

有什么想法吗 ?

在厨房应用程序iOS,厨师应用程序的链接发生类似的事情:https://itunes.apple.com/us/app/cook/id687560846?mt = 8

PS:我已添加动画,gif将在完全加载后不间断运行.

动画

animation android android-animation

15
推荐指数
1
解决办法
1987
查看次数

设置FloatingActionButton纹波

我试图将FloatingActionButton纹波设置为类似于此的东西

从材料设计.

问题是我只得到一个没有波纹的"平面样式",它只是将按钮从我的情况下改变为白色到橙色而没有上面链接中显示的动画.

我在这里听到了答案:

带支持库的FloatingActionButton示例

但我的FAB仍然很无聊!

编辑:我目前的代码是:XML:

  <android.support.design.widget.FloatingActionButton
     android:id="@+id/item_activity_fab"
     android:layout_width="64dp"
     android:layout_height="64dp"
     android:layout_marginRight="16dp"
     android:src="@drawable/watch"
     app:borderWidth="0dp"
     app:elevation="6dp"
     app:fabSize="normal"
     app:layout_anchor="@id/item_activity_title_background"
     app:layout_anchorGravity="top|right|end"
     app:pressedTranslationZ="12dp"
     app:rippleColor="@android:color/transparent"/>
Run Code Online (Sandbox Code Playgroud)

Java的:

    mAddToWatchListFAB.setRippleColor(ContextCompat.getColor(this, R.color.orange_6));
Run Code Online (Sandbox Code Playgroud)

我在FAB上尝试了这种方法,但它似乎没有用.我也尝试了我提供的链接中的步骤

android android-animation material-design floating-action-button

15
推荐指数
2
解决办法
1万
查看次数

创建叠加ImageView动画谷歌地图

我正在尝试使我的叠加图像执行以下操作:

  • onMap/onDrag的地图,在地图中间显示一个恒定的图像,这是一个图钉
  • onTouchUp,将标记图像更改为加载标记,一旦数据加载完成,将图像加载到带有文本的新图像.

这是一个非常类似于我的问题的解决方案:

animatedMarker

到目前为止我做了什么?

  • 在我的谷歌地图中间放置了一个图像视图,并获得了使用mMap.getCameraPosition().target 该图像的图像,使用它可以得到大约中间位置坐标 setOnCameraChanged,我知道已经弃用了,还有更好的解决方案吗?
  • 剩下的部分我无法弄清楚,虽然我已经阅读了几个SO问题,声称他们已经实现了将framelayout包装在谷歌地图的片段上,并在其上应用onTouch,但也无法找到对它的正确答案.

所有这一切发生的我的xml片段如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.MovableMapFragment">

    <fragment
        android:id="@+id/map_frag_fmm"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/tablayout_global_tabs"
        android:layout_alignParentTop="true" />
<! -- long xml ahead -->
Run Code Online (Sandbox Code Playgroud)

有人知道如何实现这种行为吗?

android google-maps imageview android-animation google-maps-android-api-2

15
推荐指数
2
解决办法
1288
查看次数

活动动画从底部滑动

我用的是什么:

activity_stay.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="0%p"
        android:toYDelta="0%p" />

</set>
Run Code Online (Sandbox Code Playgroud)

activity_slide_to_bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">

    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="0"
        android:toYDelta="100%p" />

</set>
Run Code Online (Sandbox Code Playgroud)

activity_slide_from_bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">

    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="100%p"
        android:toYDelta="0" />

</set>
Run Code Online (Sandbox Code Playgroud)

启动NewActivity:

startActivity(NewActivity.getIntent(this))
overridePendingTransition(R.anim.activity_slide_from_bottom, R.anim.activity_stay)
Run Code Online (Sandbox Code Playgroud)

NewActivity完成():

finish()
overridePendingTransition(R.anim.activity_stay, R.anim.activity_slide_to_bottom)
Run Code Online (Sandbox Code Playgroud)

当NewActivity启动时,OldActivity消失 - 我看到空白的白色屏幕,NewActivity在其上方滑动到顶部.但是我需要的是我的NewActivity在启动时滑到OldActivity内容之上.我怎样才能做到这一点?

UPD:当我因为某些原因完成NewActivity时,所有动画都会完美执行:NewActivity滑到底部,OldActivity内容出现在NewActivity内容之下.

android android-animation android-xml android-activity android-transitions

15
推荐指数
3
解决办法
6844
查看次数