2014-01-30 44 views
3

我正在eclipse上處理這個android項目。我在主要活動上創建了兩個gridLayouts和一個文本字段。它繼續在窗口中顯示此警告「以下類無法實例化: - android.support.v7.widget.GridLayout(打開類,顯示錯誤日誌)」,但當我嘗試添加一個按鈕到GridLayout,活動凍結,現在它顯示以下消息「注意:此項目包含Java編譯錯誤,這可能會導致自定義視圖呈現失敗。首先修復編譯問題。渲染過程中引發的異常:com.android.layoutlib.bridge.MockView不能轉換爲android.view.ViewGroup

在呈現過程中引發異常:com.android.layoutlib.bridge。 MockView不能轉換爲android.view.ViewGroup 在窗口>顯示視圖>錯誤日誌中記錄異常詳細信息 以下類無法實例化: - android.support.v7.widget.GridLayout(Open Class,Show Error Log )「我的xml文件是:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#0099cc" 
    tools:context=".MainActivity" 
    xmlns:app="http://schemas.android.com/apk/res/com.example.simple_calculator"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="94dp" 
     android:text="" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <android.support.v7.widget.GridLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="232dp" 
     android:layout_marginTop="100dp" > 
    </android.support.v7.widget.GridLayout> 

    <android.support.v7.widget.GridLayout 
     android:layout_width="232dp" 
     android:layout_height="match_parent" 
     android:layout_marginTop="100dp" 
     app:columnCount="1" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:layout_column="0" 
      app:layout_gravity="left|top" 
      app:layout_row="0" 
      android:text="Button" /> 

    </android.support.v7.widget.GridLayout> 
</FrameLayout> 

我已經嘗試導入android-sdk- [platform]/extras/android/support/v7/gridlayout,但仍然出現同樣的錯誤。

回答

1

嘗試使用下面的代碼(我已修改了代碼,沒有添加任何其他的東西):

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#0099cc" 
    tools:context=".MainActivity" 
    xmlns:app="http://schemas.android.com/apk/res/com.example.simple_calculator"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="94dp" 
     android:text="" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <GridLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="232dp" 
     android:layout_marginTop="100dp" > 
    </GridLayout> 

    <GridLayout 
     android:layout_width="232dp" 
     android:layout_height="match_parent" 
     android:layout_marginTop="100dp" 

     > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_gravity="left" 


      android:text="Button" /> 

    </GridLayout> 
</FrameLayout> 

在這段代碼中網格佈局和應用程序:柱和重力的部分修改,並上報異常被糾正和代碼工作正常,也爲佈局規則請查看以下鏈接:

http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/ 

希望這有助於解決問題:)

最佳問候

相關問題