【问题标题】:Splashscreen background is padded闪屏背景被填充
【发布时间】:2015-08-15 09:54:25
【问题描述】:

我为我的 android 应用程序创建了一个启动画面并设置了一个背景图像。 问题是背景图像是从屏幕边框填充的。 这是布局的xml代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:paddingBottom="0dp"
    android:background="@mipmap/splashscreen_drawable"
    tools:context="quasiaffatto.myapplication.SplashScreen">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tv_logo"
    android:textColor="@color/color_white"
    android:text="App title"
    android:textSize="50sp"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:textStyle="bold"
    android:gravity="center"/>

</RelativeLayout>

为什么边框上有填充?我该如何解决?

【问题讨论】:

  • 你为什么使用这个drawable作为mipmap?您是否尝试过将其用作常规可绘制对象?
  • @Tanis.7x 我用 android studio 创建了一个图片资源,它自动将图片资源创建为 mipmap
  • 我不确定我是否理解。 Android Studio 不是图像编辑器,我不知道在其中创建图像资产的任何方法。

标签: android xml padding splash-screen


【解决方案1】:

这真的不应该发生。但是,我的第一个假设是检查该布局是针对活动还是片段。如果它用于片段,则边距可能来自父活动,特别是如果您从默认模板创建它,如果我记得在默认片段之前添加了一些边距空间。如果不是这种情况,请发布有关您的应用程序设置的更多信息。

编辑:它可能会从您的 res 文件夹中的 dimen.xml 中提取根元素的默认边距。尝试将根元素的边距设置为 0dp。

【讨论】:

  • 是的,这是一个活动的布局,我用“setContentView(R.layout.activity_splash_screen);”设置它在“onCreate”方法中..但我不明白我该如何解决这个问题。
  • 确实应该没关系,但也许尝试将根元素的边距设置为0?
  • 但根元素是RelativeLayout,我将所有填充值设置为0..
  • 填充是在任何包含的元素之前添加到元素内部的空间。边距是在元素本身被绘制之前添加到元素外部的空间。一个元素的 padding 可以包含它的部分背景,因为它被认为是元素的可绘制区域的一部分,但它的 margin 不能,因为它是为了将它与其他元素隔开。
  • 为了争论,由于我对mipmap没有太多经验,也许尝试将其背景设置为纯色,看看问题是否仍然存在?
【解决方案2】:

我找到了解决方案。 问题在于 mipmap 的使用,使用图像作为可绘制它完美地工作!

【讨论】:

    猜你喜欢
    • 2016-03-27
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多