ImageView scaleType 不起作用

ImageView scaleType doesn't work

我有一个 ImageView,其中包含一个小“?”作为图像。此图像被拉伸并且看起来很难看。所以我尝试将 ImageView.ScaleType-属性 设置为 fitCenter 但它没有任何效果。我也尝试了所有其他 scaleTypes,但没有一个影响我的布局。由于用户稍后可以在该 ImageView 中上传任意大小的图片,因此我希望我的 ImageView 始终适合它在中心。这是我的 xml-文件:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton"
            android:background="@android:drawable/ic_menu_save"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:hint="name of question"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
    </RelativeLayout>

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/imageViewQuestion"
        android:layout_gravity="center_horizontal"
        android:background="@android:drawable/ic_menu_help"
        android:layout_weight="1"
        android:cropToPadding="false"
        android:onClick="clickQuestion"
        android:scaleType="centerCrop" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textViewQuestion"
        android:layout_gravity="center_horizontal"
        android:layout_weight="0.11"
        android:textAlignment="center"
        android:hint="Question"
        android:onClick="clickQuestion"
        android:gravity="center" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.60">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="1"
            android:id="@+id/button1"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="2"
            android:id="@+id/button2"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="3"
            android:id="@+id/button3"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="4"
            android:id="@+id/button4"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />
    </LinearLayout>

</LinearLayout>

有人看到我的错误了吗?

尝试使用 src 而不是 background :

替换

android:background="@android:drawable/ic_menu_help"

来自

android:src="@android:drawable/ic_menu_help"