0
我寫了一個擴展了FrameLayout的類。新類擴展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(Open Class,Show Error Log) 有關更多詳細信息,請參見錯誤日誌(窗口>顯示視圖)。 提示:在自定義視圖中使用View.isInEditMode()可以在Eclipse中顯示時跳過代碼
當然,該應用程序不起作用。
我在做什麼錯?
你指的是關係到圖形佈局Eclipse的錯誤。這與設備上的操作無關。那麼解釋一下什麼是行不通的?它會拋出錯誤嗎?我看到的只是兩個佈局,沒有別的,如果你設置上面的佈局,它將是空的 – nandeesh