關於LinearLayout屬性android:layout_marginRight的錯誤
今天寫程序,從一個Activity跳到另一個Activity,頁面加載時出現了以下錯誤:
06-03 03:23:27.289: E/AndroidRuntime(9939): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zuo.txt/com.zuo.txt.EditPage}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
絞盡腦汁,也沒想出哪裏有問題,頁面代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:staggered="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@color/edit_select"
android:orientation="vertical" >
<TextView
android:id="@+id/spinner_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="25sp"
android:textColor="#ff0000" />
<LinearLayout
android:id="@+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/edit_select">
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="5"
android:layout_marginLeft="10dp"
android:background="@drawable/shape"
android:textSize="12sp"
/>
<ImageButton
android:id="@+id/ib_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="@+id/spinner"
android:layout_marginEnd="@+id/spinner"
android:background="@drawable/imbutton"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:contentDescription="isearch"
android:src="@drawable/ic_search" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/edit_select"
android:orientation="horizontal" >
<com.origamilabs.library.views.StaggeredGridView
android:id="@+id/staggeredGridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
staggered:drawSelectorOnTop="true"
staggered:numColumns="2" />
</LinearLayout>
</LinearLayout>
看了一些資料,發現有可能是<LinearLayout>標籤不能嵌套使用的問題,去掉裏面那個LinearLayout,發現還是有問題,接着去掉了android:layout_marginRight="@+id/save",程序運行正常,這問題蠻坑爹的,<android:layout_marginRight="@+id/save"
>居然不支持嵌套,這個問題還有待深究。
接下來,我又加上那個LinearLayout,然後只去掉,<android:layout_marginRight="@+id/save">,發現也好了,由此證明LinearLayout是可以嵌套的,應該是layout_marginRight這個屬性有問題導致的。
06-03 03:23:27.289: E/AndroidRuntime(9939): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zuo.txt/com.zuo.txt.EditPage}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
絞盡腦汁,也沒想出哪裏有問題,頁面代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:staggered="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@color/edit_select"
android:orientation="vertical" >
<TextView
android:id="@+id/spinner_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="25sp"
android:textColor="#ff0000" />
<LinearLayout
android:id="@+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/edit_select">
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="5"
android:layout_marginLeft="10dp"
android:background="@drawable/shape"
android:textSize="12sp"
/>
<ImageButton
android:id="@+id/ib_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="@+id/spinner"
android:layout_marginEnd="@+id/spinner"
android:background="@drawable/imbutton"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:contentDescription="isearch"
android:src="@drawable/ic_search" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/edit_select"
android:orientation="horizontal" >
<com.origamilabs.library.views.StaggeredGridView
android:id="@+id/staggeredGridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
staggered:drawSelectorOnTop="true"
staggered:numColumns="2" />
</LinearLayout>
</LinearLayout>
看了一些資料,發現有可能是<LinearLayout>標籤不能嵌套使用的問題,去掉裏面那個LinearLayout,發現還是有問題,接着去掉了android:layout_marginRight="@+id/save",程序運行正常,這問題蠻坑爹的,<android:layout_marginRight="@+id/save"
>居然不支持嵌套,這個問題還有待深究。
接下來,我又加上那個LinearLayout,然後只去掉,<android:layout_marginRight="@+id/save">,發現也好了,由此證明LinearLayout是可以嵌套的,應該是layout_marginRight這個屬性有問題導致的。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.