java - Android旋转动画卡顿问题

查看:626
本文介绍了java - Android旋转动画卡顿问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

在Android7.0以下的机型中会有明显的卡顿,调试信息为:Skipped 46 frames! The application may be doing too much work on its main thread.

布局为:用折叠式标题栏下放了两个ImageView用来实现动画。

  <android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:contentScrim="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|exitUntilCollapsed"
    android:fitsSystemWindows="true">
    <ImageView
        android:id="@+id/id_la"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:scaleType="fitXY"
        app:layout_collapseMode="parallax"
        android:fitsSystemWindows="true"
        android:src="@mipmap/lg_wt_bg_day_sunny"/>
    <ImageView
        android:id="@+id/id_img"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/light"/>
 </android.support.design.widget.CollapsingToolbarLayout>

但是在7。0及以上的机型运行就不会卡,如何解决卡顿问题呢?下面是两张效果图,第一张是小于7.0卡顿,第二张是7.0,很流畅

解决方案

在动画设置里设置这样一条属性强制开启硬件加速,使用硬件渲染 id_img.setLayerType(View.LAYER_TYPE_HARDWARE,null);
这样就可以了

这篇关于java - Android旋转动画卡顿问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆