显示使用 Lottie 与 AsyncTask 一起加载



我应该使用Android标准在我的应用程序中显示加载。我在洛蒂 https://lottiefiles.com/890-loading-animation 看到这个很棒的图书馆。有人可以帮助我了解如何在Android的Asynctask和Android的叠加层中使用它吗?

我能够做开始和停止动画。

您只需将其添加到您的应用程序 gradle 依赖项中

即可
dependencies {
  implementation 'com.airbnb.android:lottie:$lottieVersion'
}

并包含在布局文件中

<com.airbnb.lottie.LottieAnimationView
            android:id="@+id/originalTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="16dp"
            app:lottie_rawRes="@raw/name"
            app:lottie_autoPlay="true"
            app:lottie_loop="true"/>

@raw/名称是从 https://lottiefiles.com/890-loading-animation 下载的资源文件

您可以在 git https://github.com/airbnb/lottie-android/tree/4ea04fd194649d48b217f91c260735f7d0852187/LottieSample 上签出彩票样本

 new AsyncTask<String, String, String>() {
    /**
     * Before starting background set visibility VISIBLE to Lottie anim.
     * */
    @Override
    protected void onPreExecute() {
    }
    @Override
    protected String doInBackground(String... params) {
        // TODO fetch url data do bg process.
        return null;
    }
    /**
     * Update visibility GONE to Lottie anim..
     */
    protected void onPostExecute(String result) {
           // NO NEED to use activity.runOnUiThread(), code execute here under UI thread. 
             // Updating parsed JSON data into ListView
             final List data = new Gson().fromJson(result);
            // updating listview
            ((ListActivity) activity).updateUI(data);
    }
};

}

最新更新