【问题标题】:How to make an image of splashscreen fit all mobile screen sizes?如何使启动画面的图像适合所有手机屏幕尺寸?
【发布时间】:2019-09-28 11:35:36
【问题描述】:

我使用 (gravity:center) 用于初始屏幕的图像不适合我的移动屏幕,即使我将重力更改为填充。

<item>
    <bitmap
        android:gravity="fill"
        android:src="@drawable/drawable"/>
</item>

【问题讨论】:

  • 最好不要使用位图来拉伸整个屏幕。也许您有一些可以居中的徽标和可以使用 xml 设置的背景颜色

标签: android splash-screen gravity


【解决方案1】:

通常我对所有类型的设备都使用普通的单张图片,尺寸为 720px*1280px。 然后在我的splash_activity.xml 中,我通常以如下方式使用它:

<LinearLayout 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:layout_gravity="center"
    android:background="@drawable/bg_splash"
    android:gravity="center"
    android:orientation="vertical" />

【讨论】:

    【解决方案2】:

    使用 XML 文件中的位图作为背景

    android:background="@drawable/bg_splash"
    

    【讨论】:

      【解决方案3】:

      使用 FrameLayout 作为你的根 在其中放入一个ImageView并将ScaleType设置为fitXY并将adjustViewBounds设置为true

      所以改变你的布局如下:

       <FramLayout 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"
           >
          <ImageView 
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:scaleType="fitXY"
              android:adjustViewBounds="true"
              android:src="@drawable/bg_splash"
       />
           </FrameLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-21
        • 1970-01-01
        • 2019-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多