我已经看到很多在主 Activity 中使用 TextureView 的示例,但我正在尝试将其放入片段中。
我已经创建了最简单的示例,它的 onCreateView 被调用,onActivityCreated 也被调用,但是在传回 TextureView 后没有调用 onSurfaceTextureAvailable。
我错过了什么?
谢谢G
public class FullscreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
}
}
public class TextureViewFragment extends Fragment
implements TextureView.SurfaceTextureListener {
private TextureView mTextureView;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mTextureView = new TextureView(getActivity());
mTextureView.setSurfaceTextureListener(this);
mTextureView.setOpaque(false);
return mTextureView;
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
// TODO Auto-generated method stub
}
}
activity_fullscreen.xml:
<FrameLayout 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"
android:background="#0099cc"
tools:context=".FullscreenActivity" >
<fragment class="com.example.test.TextureViewFragment"
android:id="@+id/graphTextureView"
android:layout_width="0px" android:layout_height="match_parent" />
</FrameLayout>