java.lang.UnsupportedOperationException: 无法转换为维度: type=0x1


java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
at android.widget.ImageView.<init>(ImageView.java:137)
at android.widget.ImageButton.<init>(ImageButton.java:85)
at android.widget.ImageButton.<init>(ImageButton.java:81)

上面是错误,下面是错误的布局。我读到的所有内容都说 xml 需要一个父布局,我的布局也是如此。还有什么问题?

这是我的主要活动的布局,在应用程序启动时启动

这是我的最小/目标

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/app_name"
        android:id="@+id/textView"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:textSize="32sp"
        android:layout_centerHorizontal="true"
        android:background="#292929"
        android:gravity="center_vertical|center_horizontal"
        android:minHeight="@dimen/header_height" />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/apply"
        android:id="@+id/apply"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:textSize="24sp"
        android:background="#3fb0ff"
        android:layout_weight="1" />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/wallpaper"
        android:id="@+id/wallpapers"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:textSize="24sp"
        android:background="#3994d8"
        android:layout_weight="1" />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/request_icons"
        android:id="@+id/requesticons"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:textSize="24sp"
        android:background="#3376b4"
        android:layout_weight="1" />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/view_icons"
        android:id="@+id/viewicons"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:textSize="24sp"
        android:background="#2c5f95"
        android:layout_weight="1" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="false"
        android:layout_alignParentStart="false"
        android:measureWithLargestChild="false"
        android:orientation="horizontal">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rate"
            android:maxHeight="100dp"
            android:background="@color/transparent"
            android:src="@drawable/main_button_bottom_rate"
            android:scaleType="fitXY"
            android:layout_weight="1" />
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/gplus"
            android:maxHeight="100dp"
            android:src="@drawable/main_button_bottom_gplus"
            android:layout_weight="1"
            android:background="@color/transparent"
            android:scaleType="fitXY" />
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/morework"
            android:layout_weight="1"
            android:background="@color/transparent"
            android:maxHeight="100dp"
            android:src="@drawable/main_button_bottom_morework"
            android:scaleType="fitXY" />
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/contact"
            android:background="@color/transparent"
            android:layout_weight="1"
            android:maxHeight="100dp"
            android:src="@drawable/main_button_bottom_contact"
            android:scaleType="fitXY" />
    </LinearLayout>
</LinearLayout>

您的问题出在您的图像按钮上...我不认为 XML 膨胀器对你同时使用权重和最大高度感到满意......但它可能会传递,因为 ImageButton 上的属性之一是用于更高的 API。查看开发人员指南以了解所有这些内容,或逐个删除它们,直到崩溃消失。似乎你所有的 ImageButton 大多是相同的,所以我也会把它归结为一个进行测试......

public int getDimensionPixelSize(int index, int defValue) {
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index+AssetManager.STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return defValue;
    } else if (type == TypedValue.TYPE_DIMENSION) {
        return TypedValue.complexToDimensionPixelSize(
            data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
    }
    throw new UnsupportedOperationException("Can't convert to dimension: type=0x" // Line 463 of TypedArray.java
            + Integer.toHexString(type));
}

最新更新