Android 如何在全屏启动画面中去除图像周围的白色边框
我目前正在开发一个带有图像视图的启动屏幕。问题是,当显示启动屏幕时,图像周围有一个白色边框。因此,启动屏幕将显示周围有白色边框的图像。我想完全删除白色边框。有没有人知道这个原因或任何建议 以下是我的xml代码:Android 如何在全屏启动画面中去除图像周围的白色边框,android,xml,Android,Xml,我目前正在开发一个带有图像视图的启动屏幕。问题是,当显示启动屏幕时,图像周围有一个白色边框。因此,启动屏幕将显示周围有白色边框的图像。我想完全删除白色边框。有没有人知道这个原因或任何建议 以下是我的xml代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_wi
<?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>
在我看来,除了
图像视图
之外,您可以从布局中删除所有内容。所以看起来是这样的:
<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,直到找到一个填充屏幕的scaleType。如果这些都不起作用,我建议您提高图像文件的分辨率。我在启动页面使用的主题/样式中应用透明背景,这样我就不必扭曲显示的图像以适应设备的屏幕大小。这在使用包含透明背景的PNG文件时尤其有效 以下是我用于此“透明”主题的样式:
真的
@android:彩色/透明
@空的
真的
真的
假的
然后将此主题应用于应用程序清单中的启动活动,如下所示:
<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.setImageReSource(R.drawable.image)的图像。非常好!不是每个人都希望的一行解决方案,但效果相当好。非常感谢。啊,您可能需要将adjustViewBounds设置为false。也许它缩小了视图的大小。问题已经解决了。因为我使用dialog来显示初始屏幕,所以我需要将其设置为dialog,而不是实际屏幕
<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>