【问题标题】:Image doesn't scale properly in Android.图像在 Android 中无法正确缩放。
【发布时间】:2014-01-14 23:43:14
【问题描述】:

我正在使用 xml 可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/splashscreen"
    android:tileMode="disabled" android:gravity="top" >
</bitmap>

这是我在布局中的 imageView:

<RelativeLayout 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:id="@+id/splash_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
         />

</RelativeLayout>

但无论我做什么,它都不适合屏幕,并且只作为一个小图像出现在中心。我哪里错了?

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    可能不是最佳解决方案,因为不同设备具有不同的分辨率,但“wrap_content”将以原始分辨率显示图像。

     <RelativeLayout
            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:id="@+id/splash_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/splashscreen"
            />
        </RelativeLayout>
    

    【讨论】:

      【解决方案2】:

      尝试使用 fill_parent 每个设备都有不同的屏幕尺寸,所以你需要为每个尺寸和分辨率制作不同的启动图像我猜问题是你使用的是小尺寸(高度宽度)的图像并且显示器很大 所以你需要缩放图像以适应显示大小,这可能会使图像像素化

      【讨论】:

      • 您应该使用MATCH_PARENTFILL_PARENT 已弃用。来自ViewGroup.LayoutParamsFILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)
      • 上面的链接中没有提到“弃用”这个词。读两遍!它只是说它已被重命名(重命名!= 已弃用)。
      • 对不起,我猜 MATCH_PARENT 已重命名。但我认为其他部分是正确的,这就是我为我的解决方案所做的。为不同的屏幕尺寸制作不同的图像。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      • 2020-10-12
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      相关资源
      最近更新 更多