android - 如何在我的 Android XML 布局启动画面上将图像居中而不拉伸(stretch)

标签 android xml android-layout

这是我的代码。它将我的图像拉伸(stretch)到屏幕的宽度。我只希望它居中而不拉伸(stretch)。我在这里弄错了什么?

    <?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="match_parent"
    android:orientation="vertical"
     >

    <ImageView
        android:id="@+id/splash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_centerHorizontal="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"         
        android:background="#FFFFFF"
        android:src="@drawable/splash_screenhdpi" />

</RelativeLayout>

最佳答案

你需要设置一个scaleType android:scaleType="center"

关于android - 如何在我的 Android XML 布局启动画面上将图像居中而不拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31351128/

相关文章:

java - 对话框打开时检测后退按钮事件

xml - 在 vb/net 中读取 XML 文件时出现 System.IO.FileNotFoundException

java - 记录 SOAP 消息时如何忽略 base64binary 字段?

安卓布局 : 1 imageview on fixed position and 2 imageviews fill up the remaining space

android - 如何在没有欢迎 Appcelerator 屏幕的情况下启动移植到 Android 的 Titanium 应用程序?

java - 我的 AppWidgetProvider 会在 onReceive 中从 3rd 方应用程序接收数据的可能原因是什么?

c# - DataSet Merge 和 AcceptChanges 以获得 DiffGram

java - fragment inflater 中的空指针异常

android - 如何查看特定 ListView 项的详细数据

android - 将大文件(约 2MB)上传到服务器