0

インスタンスでオーバーレイしようとしてfragmentcameraPreviewます。レイアウトのルートにはfragmentxml タグがあり<surfaceviewます。アプリを実行するとクラッシュし、以下のエラーがスローされます。なぜそれが起こるのですか?

Class_Extends_Fragment:

    public class CameraPreviewFragment extends Fragment {

private CustomCameraView mCameraPreview = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    mCameraPreview = new CustomCameraView(this.getActivity());
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    View view = inflater.inflate(R.layout.camerapreviewfragment, null);
    return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    SurfaceView sv = (SurfaceView) getView().findViewById(R.id.surfaceView);

}

MainActivity_layout:

<?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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fragmentwithcamerasurface.MainActivity"
tools:ignore="MergeRootFrame">
    <fragment
        android:name="com.example.fragmentwithcamerasurface.CameraPreviewFragment"
        android:id="@+id/fragment00ID"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </fragment>

fragmentRoot_layout:

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="MergeRootFrame"
android:background="#ffff00">

<!--logcat complains about this line-->
    <com.example.fragmentwithcamerasurface.CustomCameraView
    android:id="@+id/surfaceView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"/>

logCat:

 05-28 09:34:13.670: E/AndroidRuntime(11327): java.lang.RuntimeException: Unable to  
 start activity   
 ainActivity}: android.view.InflateException: Binary XML file line #11: Error  
 inflating class com.example.fragmentwithcamerasurface.CustomCameraView
 05-28 09:34:13.670: E/AndroidRuntime(11327): java.lang.RuntimeException: Unable to 
 start activity  
 ainActivity}: android.view.InflateException: Binary XML file line #11: Error   
 inflating class com.example.fragmentwithcamerasurface.CustomCameraView
 05-28 09:34:13.670: E/AndroidRuntime(11327):   at  
4

2 に答える 2

0

フラグメントのルート レイアウトとして間違ったレイアウト ファイルを使用しています。getView() でインフレートするレイアウト ファイルは、フラグメント自体ではなく、フラグメント内で表示するビューを指定するファイルである必要があります。

レイアウト インフレータは再帰的に 25 ステップの深さしかないと思います。


falseの 3 番目の引数として追加する必要がありLayoutInflater.inflateます。

CameraPreviewFragmentはありませんContext

于 2014-05-28T06:47:48.207 に答える
0

まず R.layout.camerapreviewfragment で膨らませますが、作成しているレイアウトは fragmentRoot_layout であり、

tools:context="com.example.fragmentwithcamerasurface.CameraPreviewFragment"  

CameraPreviewFragment はコンテキストではありません

tools:context の詳細については、これをチェックしてください。

于 2014-05-28T07:01:27.793 に答える