Android 原因:java.lang.UnsupportedOperationException:Can';t转换为尺寸:类型=0x12
您好,我正在开发应用程序。我的应用程序在所有设备上都能完美运行。但当我们在mdpi phone上运行此应用程序时,会出现以下错误:Android 原因:java.lang.UnsupportedOperationException:Can';t转换为尺寸:类型=0x12,android,android-layout,Android,Android Layout,您好,我正在开发应用程序。我的应用程序在所有设备上都能完美运行。但当我们在mdpi phone上运行此应用程序时,会出现以下错误: 原因:java.lang.UnsupportedOperationException:无法转换为维度:type=0x12。 在我错的地方请帮助我 这是我的代码:- 使用一个父布局并使用下面的XML代码而不是您的代码,它将解决您的问题 <RelativeLayout xmlns:android="http://schemas.android.com/ap
原因:java.lang.UnsupportedOperationException:无法转换为维度:type=0x12。
在我错的地方请帮助我
这是我的代码:-
使用一个父布局并使用下面的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>
今天刚开始接受这个,所以发现了导致它的变化。 在我的例子中,这是因为我必须为新设备创建一个新的布局目录布局xhdpi。 现在,新设备认为它是“大的”(即,它使用的布局在布局大);但它实际上是xhdpi 因此,在新的布局xml文件中,我添加了对values large/dimens.xml中值的引用 然而,这不起作用 创建包含引用值的xhdpi/dimens.xml值解决了这个问题
TL;DR确保每个布局都有一个值-XXXXX目录-XXXXX目录,并且所有相关值都在其中。我相信适用于所有尺寸的值都可以在values/dimens.xml中找到,但这不是我的应用程序的结构,因此我无法证明这一点。@Rishabh.CreatioSoft使用一个父布局。可能重复的我也会遇到类似的错误。你知道为什么这只发生在HTC手机上吗?你能不能告诉我到底是哪条线路出了问题?没人想一行一行地读这些来弄明白。谢谢。Android显示器的“大小”(例如“大”)与显示密度正交。也就是说,您可以有一个大尺寸的xhdpi屏幕和一个中等尺寸的xhdpi屏幕。此外,还有资源限定符优先级规则可以解释您看到的行为。
<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>