获取"错误无法转换为维度类型0x12"

时间:2014-03-24 17:40:51

标签: android dimension

我正在开发一个Android启动器,我在某些手机上收到错误“无法转换为维度类型0x12”。我已经读到这可能是因为屏幕密度,但我找不到任何值得注意的错误。 这是我的xml文件:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/home_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@color/Super_Black_Trans"
        android:gravity="center"
        android:orientation="horizontal" >

        <AutoCompleteTextView
            android:id="@+id/home_search"
            android:layout_width="fill_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:layout_weight="1"
            android:background="#00000000"
            android:dropDownVerticalOffset="0dp"
            android:gravity="center|left"
            android:hint="@string/search_for"
            android:maxLines="1"
            android:paddingLeft="20dp"
            android:popupBackground="@color/Super_Black_Trans"
            android:textColor="#C0C0C0"
            android:textSize="25sp" />

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:gravity="center" >

            <ImageButton
                android:id="@+id/settings_button"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_alignParentRight="true"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:background="@drawable/activity_settings"
                android:gravity="center"
                android:onClick="onSettings" />
            <!-- android:background="@drawable/activity_settings" -->


            <!-- android:onClick="onSettings" -->

            <ImageButton
                android:id="@+id/search_button"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_alignParentRight="true"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:background="@drawable/ic_action_search"
                android:gravity="center"
                android:onClick="onSearch" />
        </FrameLayout>
    </LinearLayout>
    <!-- So That I can add header to GridView easily -->

    <ScrollView
        android:id="@+id/grid_scroll_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <!--
 <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:background="@color/Super_Black_Trans"
    android:orientation="horizontal"/>
            -->

            <com.codiaq.launcher.alpha.ExpandableHeightGridView
                android:id="@+id/home_content"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:numColumns="4"
                android:padding="5dp"
                android:scrollbars="none" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

<GridView
    android:id="@+id/left_drawer"
    android:layout_width="85dp"
    android:layout_height="fill_parent"
    android:layout_gravity="start"
    android:background="@color/Mega_Black_Trans"
    android:choiceMode="singleChoice"
    android:footerDividersEnabled="true"
    android:gravity="center"
    android:numColumns="1"
    android:padding="5dp" />

</android.support.v4.widget.DrawerLayout>

这是我生成问题的onCreate活动。

    @SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
sh = new SettingsHandler(this);
super.onCreate(savedInstanceState);
final int[] ITEM_DRAWABLES = { R.drawable.ic_action_settings, R.drawable.ic_icon_device_settings, R.drawable.ic_icon_google_play};
    setContentView(R.layout.activity_main_launch_screen);
    drawer = (GridView)findViewById(R.id.left_drawer);
    mDrawer = (android.support.v4.widget.DrawerLayout)findViewById(R.id.drawer);
    ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) drawer
            .getLayoutParams();
    sidebarItems = new FunctionsM[]{
            new FunctionsM(getString(R.string.phone)),
            new FunctionsM(getString(R.string.contacts)),
            new FunctionsM(getString(R.string.texts)),
            new FunctionsM(getString(R.string.music)),
            new FunctionsM(getString(R.string.email)),
            new FunctionsM(getString(R.string.browser))

    };
    searchButton = (ImageButton)findViewById(R.id.search_button);
    settingsButton = (ImageButton)findViewById(R.id.settings_button);
    searchButton.setVisibility(View.GONE);
    homeView = (LinearLayout)findViewById(R.id.home_view);
    home_grid = (ExpandableHeightGridView)findViewById(R.id.home_content);
    home_grid.setExpanded(true);
    home_view_search = (AutoCompleteTextView)findViewById(R.id.home_search);
    mDrawer.setScrimColor(getResources().getColor(android.R.color.transparent));
    GridScrollView = (ScrollView)findViewById(R.id.grid_scroll_view);
    cmd = new PubCommands(this, MainLaunchScreen.this);
    home_grid.setPadding(0, 0, 0, cmd.getNavHeight());
    if (Build.VERSION.SDK_INT >= 19){
        statbar_height = cmd.calcStatBar();
        homeView.setPadding(0, statbar_height,0,0);
        }
    int actionBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
    {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
    }
    int value = statbar_height + actionBarHeight;
    mlp.setMargins(0, value, 0, - value);
    drawer.setLayoutParams(mlp);
    //drawer.setPadding(0, statbar_height + actionBarHeight, 0, 0);

}

最后,这是m stacktrace:

    03-24 17:32:08.938: E/AndroidRuntime(1265): FATAL EXCEPTION: main
03-24 17:32:08.938: E/AndroidRuntime(1265): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.codiaq.launcher.alpha/com.codiaq.launcher.alpha.MainLaunchScreen}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.os.Looper.loop(Looper.java:137)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.ActivityThread.main(ActivityThread.java:4745)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at java.lang.reflect.Method.invokeNative(Native Method)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at java.lang.reflect.Method.invoke(Method.java:511)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at dalvik.system.NativeStart.main(Native Method)
03-24 17:32:08.938: E/AndroidRuntime(1265): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5612)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1809)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1721)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:58)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:748)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2784)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2844)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:252)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.Activity.setContentView(Activity.java:1867)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at com.codiaq.launcher.alpha.MainLaunchScreen.onCreate(MainLaunchScreen.java:94)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.Activity.performCreate(Activity.java:5008)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-24 17:32:08.938: E/AndroidRuntime(1265):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-24 17:32:08.938: E/AndroidRuntime(1265):     ... 11 more

这里也是我的manifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.codiaq.launcher.alpha"
    android:versionCode="9"
    android:versionName="1.0.1" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="19" />

[.....]

</manifest>

1 个答案:

答案 0 :(得分:0)

尝试将父版面添加到:

<android.support.v4.widget.DrawerLayout

例如LinearLayout

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

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >

...
...
...