【发布时间】:2012-11-27 10:31:21
【问题描述】:
我写了一个扩展 FrameLayout 的类。
public class ReaderFrameLayout extends FrameLayout
{
public ReaderFrameLayout(Context context)
{
this(context, null);
}
public ReaderFrameLayout(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public ReaderFrameLayout(Context context, AttributeSet attrs, int defaultStyle)
{
super(context, attrs, defaultStyle);
WebView readerWebView = (WebView) findViewById(R.id.fragment_reader_webview);
readerWebView.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
Log.d("ReaderFrameLayout", "setOnTouchListener");
return true;
}
});
}
}
并将其添加到片段中。
<RelativeLayout 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" >
<com.mbs.helpers.ReaderFrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="83dp" >
<WebView
android:id="@+id/fragment_reader_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</com.mbs.helpers.ReaderFrameLayout>
</RelativeLayout>
Eclipse 中的错误:
com.android.layoutlib.bridge.MockView 无法转换为 android.view.ViewGroup 异常详细信息记录在窗口 > 显示视图 > 错误日志中 无法实例化以下类: - com.mbs.helpers.ReaderFrameLayout(开放类,显示错误日志) 有关详细信息,请参阅错误日志(窗口 > 显示视图)。 提示:在自定义视图中使用 View.isInEditMode() 在 Eclipse 中显示时跳过代码
当然,该应用程序不起作用。
我做错了什么?
【问题讨论】:
-
您所指的eclipse错误与图形布局有关。这与设备上的操作没有任何关系。那么请解释什么不起作用?它会抛出错误吗?我看到的只是两个布局,没有别的,如果你设置上面的布局,它将是空的