【问题标题】:How to remove the white border around the image in splash screen in full screen如何在全屏启动画面中删除图像周围的白色边框
【发布时间】:2013-04-11 01:52:29
【问题描述】:

我目前正在处理带有图像视图的启动画面。问题是当显示启动画面时,图像周围有一个白色边框。这样启动画面就会显示带有白色边框的图像。我想完全删除白色边框。有没有人知道这样做的原因或任何建议?

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <View android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ImageView android:id="@+id/ImageViewSplash"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:contentDescription="@string/splashImageContentDescription" />
</RelativeLayout>

【问题讨论】:

  • 为什么布局中有任意的View?

标签: android xml


【解决方案1】:

我在用于启动页面的主题/样式中应用了透明背景,这样我就不必扭曲正在显示的图像以适应设备的屏幕尺寸。这在使用包含透明背景的 PNG 文件时特别有效。

这是我用于这个“透明”主题的风格:

    <style name="Theme.Transparent" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>

然后将此主题应用到应用程序清单中的启动活动,如下所示:

    <activity
        android:name="com.masseria.homework9.SplashActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/Theme.Transparent" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

【讨论】:

  • 我试过让relativelayout和in的背景色透明,还是不行。
  • 如何将图像加载到 ImageView 中?
  • 我在代码中使用 img.setImageReosource(R.drawable.image) 加载图像。
  • 太棒了!不是每个人都希望的单线解决方案,但效果很好。谢谢!
【解决方案2】:

在我看来,您可以从布局中删除除 ImageView 之外的所有内容。所以它看起来像这样:

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ImageViewSplash"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:contentDescription="@string/splashImageContentDescription" />

然后您可以在图像上使用 scaleType 直到找到填满屏幕的类型。如果这些都不起作用,我建议您提高图像文件的分辨率。

【讨论】:

  • 啊,您可能需要将 adjustViewBounds 设置为 false。也许它正在缩小视图的大小。
  • 问题已解决。由于我使用对话框来显示启动画面,所以我需要将其设置为对话框,而不是实际屏幕
猜你喜欢
  • 1970-01-01
  • 2017-10-28
  • 2017-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-24
  • 1970-01-01
相关资源
最近更新 更多