android - 启动画面上的进度条

Joh*_*EDU 7 java xml android splash-screen progress-bar

我的应用程序在加载时显示启动画面。我想在初始屏幕上的图标下方放置一个动画进度条。我尝试使用 XML,但它崩溃了!说无效的标签进度条。

这是我在styles.xml 中调用闪屏的代码

<style name="AppTheme.BrandedLaunch" parent="AppThemeDark">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这是我的 background_splash.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:drawable="@color/splash_screen_bg"/>

<item>
    <bitmap
        android:gravity="center"
        android:tileMode="disabled"
        android:src="@drawable/ic_launcher"/>
</item>

<item>
<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
/>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

我真的不想使用不同的方法制作启动画面,因为这种方法非常简单。有任何想法吗?

小智 0

不要将进度条和图像视图(位图)等小部件放在可绘制文件中,而是将其添加到布局文件中,其中父布局应为相对布局,然后将相对布局背景颜色设置为splash_screen_bg,并将图像视图和进度条添加到相对布局内。