2012-04-06 77 views
0

我需要帮助...我买了我的Android XML错误...下面的代码:的Android ::设置布局

<?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

这是什么代码? com.android.layoutlib.bridge.MockView – MAC 2012-04-06 14:30:58

+0

“com.android.layoutlib.bridge.MockView无法转换为android.view.ViewGroup”是错误消息。我的xml代码出现问题.. – user1271277 2012-04-06 14:40:12

+0

@ user1271277:发布您的MockView布局 – 2012-04-06 15:07:21

回答

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> 
+0

已经尝试。它没有显示布局..仍然是我得到的错误.. – user1271277 2012-04-06 15:37:41

+0

是否有错误的Eclipse即时消息使用现在? – user1271277 2012-04-06 16:46:00

+0

@ user1271277:也许尝试建立或清洁并重新启动Eclipse – 2012-04-06 16:47:44

0

在您可能忘记将layout_width添加到视图的布局xml文件。该属性对于xml文件中的任何视图都是必需的。

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这使用自定义视图。