Android 在 ImageView 上使用缩放类型作为 centerCrop 不执行任何操作

Android using scale type as centerCrop on ImageView does nothing

我正在尝试居中裁剪我的图像,但它似乎不起作用。这是布局文件:

<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"
    android:background="@color/bg_block_list"
    tools:context="com.contag.app.fragment.NavDrawerFragment">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <RelativeLayout
                android:id="@+id/rl_drawer_header"
                android:layout_width="match_parent"
                android:layout_height="150dp">

                <ImageView
                    android:id="@+id/iv_nav_drawer_header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:background="@drawable/default_profile_pic"
                     />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/bg_user_activity"
                    android:orientation="vertical"
                    android:paddingLeft="30dp">

                    <android.support.v7.widget.AppCompatTextView
                        android:id="@+id/tv_usr_name"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:textColor="@color/white"
                        android:text="Name"
                        android:textSize="20sp" />

                    <android.support.v7.widget.AppCompatTextView
                        android:id="@+id/tv_usr_cunt_id"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:textColor="@color/white"
                        android:textSize="16sp" />
                </LinearLayout>

            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/rl_notification_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/light_blue"
                android:padding="10dp">

                <TextView
                    android:id="@+id/tv_notification_txt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="20dp"
                    android:text="@string/notification"
                    android:textColor="@color/white"
                    android:onClick="onClick"
                    android:clickable="true"
                    android:textSize="20sp" />

            </RelativeLayout>

        </LinearLayout>
    </ScrollView>
</RelativeLayout>

我已经缩短了 xml 以便在此处发布,特别是证明使用 scrollView 的部分。我做错了什么?

附上我得到的输出。

将下面的代码更改为:

 <ImageView
                    android:id="@+id/iv_nav_drawer_header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:background="@drawable/default_profile_pic"
                     />

收件人:

<ImageView
                    android:id="@+id/iv_nav_drawer_header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:src="@drawable/default_profile_pic"
                     />

根据您的要求,您必须设置图片视图的 width and height as wrap_contentsrc 而不是 background .