在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>在线等答案!!!!!!!!
<?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>在线等答案!!!!!!!!
楼主明白这个提示的意思吧?
就是说类转换异常,不能把ImageView转换为ViewGroup.
也就是说不能把ImageView当做ViewGroup来用,简单点说就是不能在ImageView里面包含其他控件;而楼主的layout中ImageView里面还嵌套了LinearLayout, LinearLayout下又嵌套了TableLayout, ...
{ public MyViewPager(Context context, AttributeSet attrs) {
super(context,attrs);
} @Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
return false;
}
}请问这样写不行么?还需要重写什么方法呢?