Android ::设置布局

时间:2012-04-06 14:28:58

标签: android android-xml

我需要帮助......我的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.

提前致谢..

3 个答案:

答案 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)

在您的布局xml文件中

,您可能忘记将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 。