src 可绘制对象未显示在屏幕中

The src drawable doesn't show up in the screen

我使用CircularImageView 来设置人物的头像。出于某种原因,我无法弄清楚为什么图像的占位符没有显示在配置文件屏幕中。当用户没有设置任何个人资料图像时,图像的占位符根本不会显示。但是当我在同一页面中使用相机或画廊意图设置图像时,它会在占位符中显示图像。我不知道是什么问题。请帮助我为什么它不显示默认的 src 属性,当用户在配置文件 CircularImageView 中没有任何图像时。

在下方发布 xml 文件。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">

<android.support.constraint.ConstraintLayout

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.project.group.projectga.fragments.ProfileFragment">


    <android.support.constraint.ConstraintLayout
        android:id="@+id/photoLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:id="@+id/profileBackground"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:scaleType="fitCenter"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/profile_background"
            tools:ignore="ContentDescription" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:orientation="horizontal"
            android:padding="10dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/photoCircle">

            <mehdi.sakout.fancybuttons.FancyButton

                android:id="@+id/cameraButton"
                style="@style/fancyButtonProfile"
                app:fb_defaultColor="@color/colorPrimary"
                app:fb_radius="30dp"
                app:fb_text="Camera"
                app:fb_textSize="15sp" />

            <mehdi.sakout.fancybuttons.FancyButton
                android:id="@+id/galleryButton"
                style="@style/fancyButtonProfile"
                android:layout_marginStart="10dp"
                android:layout_toEndOf="@+id/cameraButton"
                app:fb_defaultColor="@color/colorPrimary"
                app:fb_radius="30dp"
                app:fb_text="Gallery"
                app:fb_textSize="15sp" />

            <mehdi.sakout.fancybuttons.FancyButton
                android:id="@+id/removeButton"
                style="@style/fancyButtonProfile"
                android:layout_marginStart="10dp"
                android:layout_toEndOf="@+id/galleryButton"
                app:fb_borderColor="@color/colorPrimary"
                app:fb_borderWidth="2dp"
                app:fb_defaultColor="@android:color/transparent"
                app:fb_radius="30dp"
                app:fb_text="Remove"
                app:fb_textColor="@color/colorPrimary" />

        </RelativeLayout>

        <android.support.constraint.ConstraintLayout
            android:id="@+id/photoCircle"
            android:layout_width="128dp"
            android:layout_height="128dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <com.mikhaellopez.circularimageview.CircularImageView
                android:id="@+id/circularPhoto"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_centerInParent="true"
                android:cropToPadding="true"
                android:scaleType="centerCrop"
                android:src="@drawable/ic_account_circle_white_24dp"
                app:civ_shadow="true"
                app:civ_shadow_radius="24"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />


        </android.support.constraint.ConstraintLayout>

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.ConstraintLayout
        android:id="@+id/aboutDividerLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="24dp"
        android:layout_marginStart="24dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/photoLayout">

        <ImageView
            android:id="@+id/aboutDivider"
            android:layout_width="336dp"
            android:layout_height="2dp"
            android:background="@color/md_grey_300"
            android:scaleType="fitXY"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@android:drawable/divider_horizontal_bright"
            tools:ignore="ContentDescription" />

        <TextView
            android:id="@+id/aboutLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:background="@color/md_light_background"
            android:paddingLeft="8dp"
            android:paddingRight="8dp"
            android:text="@string/aboutLabel"
            android:textAlignment="center"
            android:textColor="@color/accent"
            android:textSize="12sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

这是第一次创建用户时的图像。

这是在使用图库设置图片后设置个人资料图片后。

在此先致谢,如有任何帮助,我们将不胜感激。这是我在片段中加载图片的地方

Picasso.with(getContext()).load(profile.getProfile()).error(R.drawable.ic_error_outline_black_24dp).into(circularProfilePhoto);

如果您的 objective 是显示默认图像,那么您可以通过 Activity/Fragment 中的代码设置默认图像:

findViewById(R.id.circularPhoto).setBackgroundResource(R.drawable.chrysanthemum) 

android:background = "@drawable/ic_account_circle_white_24dp"  

xml 中的属性。

我不明白为什么图像没有显示在 xml 中,即使您使用 android 命名空间 src 用于显示可绘制对象的属性。如果它是其他命名空间,那么 aapt 会将其视为自定义属性。我试图在我的代码中使用 android:src 属性显示默认图像并且它起作用了。

<LinearLayout 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:orientation="vertical">

<com.mikhaellopez.circularimageview.CircularImageView
    android:id="@+id/circularImageView"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_gravity="center_horizontal"
    android:layout_margin="20dp"
    android:src="@drawable/chrysanthemum"
    />

</LinearLayout>

但是这个在 xml 中不起作用,我需要从代码中设置图像以使其工作:

<LinearLayout 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:orientation="vertical">

<com.mikhaellopez.circularimageview.CircularImageView
    android:id="@+id/circularImageView"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_gravity="center_horizontal"
    android:layout_margin="20dp"
    app:src="@drawable/chrysanthemum"
    />

</LinearLayout>

让我知道它是否适合你。