【问题标题】:Show bg image with progress-bar on splash screen在初始屏幕上显示带有进度条的 bg 图像
【发布时间】:2020-02-12 21:45:48
【问题描述】:

我正在尝试在初始屏幕上显示背景图像和进度条。

splash.xml 的代码

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_height="match_parent" android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/spalsh">
        <ProgressBar
            android:id="@+id/loading"
            style="?android:progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:indeterminateDrawable="@layout/progressbartemplate"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center"
            android:layout_marginBottom="10dp" />
</FrameLayout>

然后我有样式

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:background" >@layout/splash</item>
    </style>

然后我将这个样式应用到manifiestfile中的Activity

<activity
            android:name="com.test.SplashActivity" android:theme="@style/SplashTheme"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

但是当应用程序启动时,我看不到图像和进度条,而我可以在设计视图中看到。 如果我使用 Layer-List 并删除进度条,相同的代码将起作用。

有人可以建议我如何在底部显示带有进度条的 bg 图像吗?

提前致谢

【问题讨论】:

  • 如果您有专门的启动活动,则将进度放入其 layout.xml 文件并显示特定时间,然后完成活动
  • 还可以查看this 以了解不同的显示方式
  • @MohammedAlaa 如果我使用活动的布局来显示启动画面,那么当他第一次点击应用程序启动它时,用户可以看到一段时间的空白屏幕。
  • @Paven Tiwari 是的,你是对的,但你正在做的是你需要将 xml 布局文件作为背景,对吗?我不知道这是否可行,因为你怎么能膨胀这个布局并且活动还没有开始?
  • @MohammedAlaa 正如我在问题中提到的,“如果我使用图层列表并删除进度条,相同的代码将起作用。”我想知道为什么

标签: android android-layout android-activity splash-screen android-theme


【解决方案1】:

我认为启动图像的大小有问题,您必须按照打击步骤调整它的大小

1-右键点击res

2-右键点击drawable

3-点击新建

4- Batch Drawable 导入器

5-点击加号+选择飞溅

希望对你有帮助

【讨论】:

    【解决方案2】:

    试试这个,希望能解决你的问题。

    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@mipmap/ic_launcher"
        tools:context="com.example.viral.myapplication.MainActivity">
    
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:padding="12dp"/>
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 2019-03-07
      • 2017-10-17
      相关资源
      最近更新 更多