为什么Android选择错误的密度图像?

时间:2017-09-17 03:32:23

标签: android android-drawable

我有一个协调器布局和一个ImageView用于配置文件照片,它应该从ActionBar“挂起”。问题是Android从不同的密度可绘制文件夹中选择了错误的图像。以下是布局的外观:

enter image description here

你可以在这里看到图像几乎覆盖整个屏幕(不应该)。以下是我在相应文件夹中提供的各种可绘制尺寸:

  • drawable-mdpi / avatar.png | 310x310px
  • drawable-hdpi / avatar.png | 465x465px
  • drawable-xhdpi / avatar.png | 621x621px
  • drawable-xxhdpi / avatar.png | 931x931px

现在,为什么Android不会像覆盖一个小区域那样显示图像(就像根据mdpi一样)?

(上述测试屏幕为xxhdpi)

注意: 图像已在Photoshop Artboard中创建,我们假设桌面密度为mdpi,而移动设备中的其他密度则可放大/缩小。

参考代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/main.appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/main.appbar"
        app:layout_anchorGravity="bottom|center"
        android:src="@drawable/avatar"/>



</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:0)

为什么你认为个人资料图片应该很小?您的标准现代手机有大约360-400水平dp;如果您的mdpi图像是310x310(并且其余图像相应地缩放),那么我希望图像几乎与普通手机一样宽。

根据您发布的尺寸,所有内容似乎都正常工作。