0

助けが必要です... 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.

前もって感謝します..

4

3 に答える 3

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>
于 2012-04-06T15:28:46.350 に答える
0

レイアウト xml ファイルで、ビューに追加するのを忘れている可能性がありlayout_widthます。この属性は、xml ファイル内のすべてのビューに必要です。

于 2012-04-06T15:32:33.440 に答える
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_widthlayout_heightを定義する必要があります。

于 2012-04-06T15:55:19.450 に答える