首页 > 解决方案 > 应用启动时 loading_animation 显示不清楚

问题描述

我在 Github 有以下项目:https ://github.com/AliRezaeiii/Contacts

当我启动应用程序(创建一个新的应用程序实例)时,进度条图像在几毫秒内不清楚,但后来它按预期出现:

在此处输入图像描述

我意识到这是由于我的 ViewPager 在 MainActivity :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="wrap_content"
    android:layout_height="wrap_content"
    tools:context=".ui.MainActivity">

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_behavior=".behavior.QuickHideBehavior">

        <com.sample.android.contact.widget.ListenableTabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_alignParentBottom="true"
            android:background="@color/colorPrimary"
            app:tabIndicatorHeight="2dp"
            app:tabSelectedTextColor="@color/colorAccent"
            app:tabTextColor="@android:color/white" />

</android.support.design.widget.CoordinatorLayout>

当我删除 ViewPager 时,进度条图像按预期出现在开始时。

这是我在 ViewPager 片段中的 imageView:

<?xml version="1.0" encoding="utf-8"?>
<com.sample.android.contact.widget.NestedCoordinatorLayout 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=".ui.ContactsFragment">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Toolbar
            android:layout_width="match_parent"
            android:layout_height="?android:actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways">

    </android.support.design.widget.AppBarLayout>

    <com.sylversky.indexablelistview.widget.IndexableRecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layoutManager="LinearLayoutManager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <ImageView
        android:id="@+id/progressBar"
        android:layout_width="170dp"
        android:layout_height="170dp"
        android:layout_gravity="center"
        tools:ignore="contentDescription"
        tools:src="@drawable/loading_animation" />

</com.sample.android.contact.widget.NestedCoordinatorLayout>

当我使用 Handler post delay 设置图像时,它再次按预期显示:

 mHandler.postDelayed(() -> mProgressBar.setImageResource(R.drawable.loading_animation), 0);

但是不使用Handler,就不清楚了。

可能是什么原因以及如何解决?

这是 loading_animation :

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/loading_img"
    android:pivotX="50%"
    android:pivotY="50%" />

标签: androidandroid-imageview

解决方案


推荐阅读