我需要帮助......我的android xml出错...这是代码:
<?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>
以下是错误消息:
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.
提前致谢..
答案 0 :(得分:0)
试试这个:
<?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>
答案 1 :(得分:0)
,您可能忘记将layout_width
添加到视图中。
答案 2 :(得分:0)
<?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>
从上面的代码中,您可以看到如何定义自定义视图 com.marlonlu.pinterest.ui.module.GallaryView ,在Android中,您必须定义 layout_width 和<您使用自定义视图在布局中使用strong> layout_height 。