2

嗨,我正在开发应用程序。我的应用程序在所有设备上都能完美运行。但是当我们在 mdpi 手机上运行这个应用程序时,它给我这个错误:

Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12.

请在我错的地方帮助我。

这是我的代码:-

<RelativeLayout
    android:id="@+id/LevLayId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="140dp" >

    <TextView
        android:id="@+id/totlScorId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:background="@drawable/score_timer"
        android:gravity="center"
        android:textColor="#ffffff" />

    <TextView
        android:id="@+id/levelId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@drawable/score_timer"
        android:gravity="center"
        android:textColor="#ffffff" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/LayAboButId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/option_last_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="7px"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/opt3Btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/option_normal_new"
            android:gravity="center|center_vertical"
            android:textColor="#ffffff"
            android:textSize="11dp" />

        <Button
            android:id="@+id/opt4Btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/option_normal"
            android:gravity="center|center_vertical"
            android:textColor="#ffffff"
            android:textSize="11dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/option_pre_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/option_last_row"
        android:layout_marginBottom="3px"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/opt1Btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/option_normal_new"
            android:gravity="center|center_vertical"
            android:textColor="#ffffff"
            android:textSize="11dp" />

        <Button
            android:id="@+id/opt2Btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/option_normal"
            android:gravity="center|center_vertical"
            android:textColor="#ffffff"
            android:textSize="11dp" />
    </LinearLayout>
</RelativeLayout>

<RelativeLayout
    android:id="@+id/imgLayId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="70dp"
    android:layout_marginRight="@id/totlScorId"
    android:layout_marginTop="70dp" >

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <ImageView
        android:id="@+id/imgViewId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <ImageView
        android:id="@+id/imgViewframeId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/photo_frame" />
</RelativeLayout>

4

2 回答 2

2

使用一种父布局并使用下面的 XML 代码而不是您的代码,它将解决您的问题。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/LevLayId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="140dp" >

        <TextView
            android:id="@+id/totlScorId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/score_timer"
            android:gravity="center"
            android:textColor="#ffffff" />

        <TextView
            android:id="@+id/levelId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="@drawable/score_timer"
            android:gravity="center"
            android:textColor="#ffffff" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/LayAboButId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/option_last_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="7px"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/opt3Btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/option_normal_new"
                android:gravity="center|center_vertical"
                android:textColor="#ffffff"
                android:textSize="11dp" />

            <Button
                android:id="@+id/opt4Btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/option_normal"
                android:gravity="center|center_vertical"
                android:textColor="#ffffff"
                android:textSize="11dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/option_pre_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/option_last_row"
            android:layout_marginBottom="3px"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/opt1Btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/option_normal_new"
                android:gravity="center|center_vertical"
                android:textColor="#ffffff"
                android:textSize="11dp" />

            <Button
                android:id="@+id/opt2Btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/option_normal"
                android:gravity="center|center_vertical"
                android:textColor="#ffffff"
                android:textSize="11dp" />
        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/imgLayId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="70dp"
        android:layout_marginRight="@id/totlScorId"
        android:layout_marginTop="70dp" >

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />

        <ImageView
            android:id="@+id/imgViewId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />

        <ImageView
            android:id="@+id/imgViewframeId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/photo_frame" />
    </RelativeLayout>

</RelativeLayout>
于 2012-11-29T13:08:43.253 回答
0

今天刚开始得到这个,所以发现了导致它的变化。就我而言,这是因为我必须为新设备创建一个新的布局目录 layout-xhdpi。现在,新设备认为它是“大”的(即它正在使用 layout-large 中的布局);但它真的是 xhdpi。

所以在新的布局 xml 文件中,我添加了对 values-large/dimens.xml 中的值的引用

但是,这不起作用。

使用其中的引用值创建 values-xhdpi/dimens.xml,解决了这个问题。

TL;DR 确保每个 layout-XXXXX 目录都有一个 values-XXXXX 目录,并且所有相关值都在其中。我相信适用于所有尺寸的值都可以在 values/dimens.xml 中找到,但这不是我的应用程序的结构,所以我无法证明这一点。

于 2014-08-21T13:59:08.337 回答