首页 > 解决方案 > android.view.InflateException: Binary XML file line #6: Error inflating class。在我的包中,我做了这个类,但仍然出现错误

问题描述

android.view.InflateException: Binary XML file line #6: Error inflating class com.duplicatefilefixer.SimilarPicturesPkg.astickyheader.ui.SquareImageView 

我坚持这一点,我不知道他们会这样,因为我在同一个包中的名称路径上有类。

这是Java类

 package com.duplicatefilefixer.SimilarPicturesPkg.astickyheader.ui;

    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.ImageView;

    public class SquareImageView extends ImageView {

        public SquareImageView(Context context) {
            super(context);
        }

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

        public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); // Snap to width
        }

    }

这是我的xml

<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">

    <com.duplicatefilefixer.SimilarPicturesPkg.astickyheader.ui.SquareImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerInside"
        android:adjustViewBounds="true"
        android:layout_margin="2dp"
        android:src="@drawable/empty_photo" />

    <LinearLayout
        android:gravity="center"
        android:layout_alignBottom="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/size_txt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@android:color/white"
            android:background="#1758B6"
            android:text="5KB"
            android:gravity="center"
            android:visibility="gone"
            android:padding="5dp"/>

    </LinearLayout>

    <CheckBox
        android:focusable="false"
        android:button="@drawable/duplicate_checkbox"
        android:id="@+id/img_chk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/image"
        android:layout_alignRight="@+id/image"
        android:layout_alignEnd="@+id/image"
        android:paddingTop="5dp"
        android:paddingRight="5dp"
        android:paddingEnd="5dp"
        android:layout_marginTop="5dp"/>

</RelativeLayout>

标签: androidandroid-layout

解决方案


推荐阅读