android - 应用启动时 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%" />
解决方案
推荐阅读
- sql - sql查询排序但在顶部显示特定值
- perl - Perl 用字符串死而不附加文件名和行号
- r - Rmarkdown Beamer 演示,xcolor 的选项冲突
- sql - 在没有任何明确搜索条件的情况下从长字符串中获取字符串
- traefik - Traefik 前端重定向不起作用
- r - R:将列表的所有 s4 对象合并为一个
- c# - 新的非聚集索引引发死锁
- rabbitmq - 使用 Spring AMQP 和 RabbitMQ HA 进行故障转移
- c# - 在 C# 中从 Share point office 365 读取 Excel 文件
- javascript - 将 jquery 事件与相同的类名元素分开