Android 不在imageView中显示图像

Android 不在imageView中显示图像,android,android-imageview,Android,Android Imageview,我有以下片段。无论我做什么,但图像在图像视图中不可见-:对于测试,我将按钮放在片段上,但这是refselected,但图像不可见 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto"

我有以下片段。无论我做什么,但图像在图像视图中不可见-:对于测试,我将按钮放在片段上,但这是refselected,但图像不可见

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <com.transenigma.iskconapp.DynamicImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scaleType="centerCrop"
            android:src="@drawable/img2"
            android:id="@+id/myAboutImg" />
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="8dp"
            tools:text="Text"
             />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_gravity="center_horizontal|bottom" />
    <!--</android.support.v7.widget.CardView>-->

</FrameLayout>

您想在DynamicImage视图中执行什么操作? 您可以尝试删除测量方法,并查看它们之间的差异。
可能是您的onMeasure中出错了。

尝试将此
com.transenigma.iskconapp.DynamicImageView
替换为正常的
ImageView
我已经尝试过了,但没有用。无论我做什么---您尝试过其他图像吗??从网络获取png图像,确保图像未损坏
package com.transenigma.iskconapp;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

public class DynamicImageView extends ImageView {

    public DynamicImageView(final Context context, final AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
        final Drawable d = this.getDrawable();

        if (d != null) {
            // ceil not round - avoid thin vertical gaps along the left/right edges
            final int width = MeasureSpec.getSize(widthMeasureSpec);
            final int height = (int) Math.ceil(width * (float) d.getIntrinsicHeight() / d.getIntrinsicWidth());
            this.setMeasuredDimension(width, height);
        } else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
}