在layout中用XML布局时切换到layout视图查看效果时,报ClassCastException: android.widget.ImageView can not be cast to android.view.ViewGroup,但在XML代码编辑视图中并没有错误提示,XML代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"> <ImageView android:id="@+id/top" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@drawable/top">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:stretchColumns="3,5">
<TableRow>
<ImageButton android:id="@+id/arrowleft"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/arrowleft" android:layout_column="0">
</ImageButton>
</TableRow>
</TableLayout>
</LinearLayout>
</ImageView> <WebView android:id="@+id/webView" android:visibility="visible"
android:layout_width="fill_parent" android:layout_height="fill_parent"></WebView> <ImageButton android:id="@+id/bottom" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@drawable/bottom">
</ImageButton></LinearLayout>在线等答案!!!!!!!!

解决方案 »

  1.   

    提示信息ClassCastException: android.widget.ImageView can not be cast to android.view.ViewGroup
    楼主明白这个提示的意思吧?
    就是说类转换异常,不能把ImageView转换为ViewGroup.
    也就是说不能把ImageView当做ViewGroup来用,简单点说就是不能在ImageView里面包含其他控件;而楼主的layout中ImageView里面还嵌套了LinearLayout, LinearLayout下又嵌套了TableLayout, ...
      

  2.   

    搞复杂了楼主参考Android的Layout整理
      

  3.   

    既然你也知道xml文件没错那为什么不把报错的代码贴出来呢?这样提问谁也帮不了你啊。
      

  4.   

    大神你好,我在重写viewpager时候也出现了这个问题,public class MyViewPager extends ViewPager
    { public MyViewPager(Context context, AttributeSet attrs) {
    super(context,attrs);

    } @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {

    return false;
    }
    }请问这样写不行么?还需要重写什么方法呢?
      

  5.   

    唔,才发现都过去三年了,不知道当年的大神还在不在csdn