Android 小部件图像的大小

Android 小部件图像的大小,android,Android,我有一个我不想缩放的图像,我正在使用fitStart。我需要制作多大尺寸才能确保它覆盖4x2小部件?我目前有一个图像是1024x768,它没有覆盖 更新: 以下是xml和屏幕截图: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widget_bg_rl" android:layout_width="match_parent" an

我有一个我不想缩放的图像,我正在使用fitStart。我需要制作多大尺寸才能确保它覆盖4x2小部件?我目前有一个图像是1024x768,它没有覆盖

更新: 以下是xml和屏幕截图:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget_bg_rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/widget_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitStart" />

    <LinearLayout 
        android:id="@+id/current_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:weightSum="8">
        <RelativeLayout
            android:id="@+id/city_time_rl"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2.5"
            android:background="@drawable/rounded_corners_top">
            <TextView
                android:id="@+id/city" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="MECHANICSBURG"
                android:textSize="16dp"
                android:textColor="@color/dk_blue"
                />


您使用的是
fitStart
,它可以保持图像的纵横比,并确保一维(在本例中为高度)精确匹配。听起来你想要这两个中的一个:

  • 如果要填充空间,显示整个图像(并根据需要拉伸),请使用
    fitXY

  • 如果要填充空间,保持图像的纵横比(并根据需要进行裁剪),请使用
    centerCrop


1024x768比当今大多数Android设备的像素都多。。那没有道理。小部件大小根据屏幕dpi的不同而变化。4x2在110dp上为250dp。我试图做到的是让图像足够大,它总是填满空间,但如果太大,它不会显示该部分。我在过去遇到的是,Android设备根据设备的不同有不同的网格(4x4、5x5…等等),我的图像被拉伸/超出比例。这是使用fitXY时发生的。@taraloca
centerCrop
。它就是这样做的。