问题
I need help... I got errors with my android xml... Here's the code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="music"
android:title="Music"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:summary="Play Music for each screen"
android:defaultValue="true" />
<CheckBoxPreference
android:key="hints"
android:title="Hints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:summary="Enable hints during gameplay"
android:defaultValue="true" />
</PreferenceScreen>
Here is the error messages:
com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
You must supply a layout_width attribute.
You must supply a layout_height attribute.
Thanks in advance..
回答1:
try this :
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="CheckBoxPreference">
<CheckBoxPreference
android:key="music"
android:title="Music"
android:summary="Play Music for each screen"
android:defaultValue="true" />
<CheckBoxPreference
android:key="hints"
android:title="Hints"
android:summary="Enable hints during gameplay"
android:defaultValue="true" />
</PreferenceCategory>
</PreferenceScreen>
回答2:
in your layout xml files you may have forgot to add layout_width
to a view. this attribute is required for any view in an xml file.
回答3:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollview_test"
android:fillViewport="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.marlonlu.pinterest.ui.module.GallaryView
android:id="@+id/gridview_test"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
</LinearLayout>
From above code, you can see how to define my custom view com.marlonlu.pinterest.ui.module.GallaryView , In Android you must define layout_width and layout_height in your layout which use custom view.
来源:https://stackoverflow.com/questions/10044898/android-settings-layout