【发布时间】:2018-09-09 04:51:11
【问题描述】:
在我的Fragment 中有一个TextureView,并且必须重新为 Layout 扩展 Fragment。我在Activity 中使用Camera API(PS:Camera API 必须在Activity 中调用),我可以使用SurfaceTexture 来获取Camera Preview。
关于如何让TextureView可以获取Camera预览的问题。我厌倦了许多解决方案,但所有解决方案都获得了空对象引用。
public class MyFragment extends PresentationFragment{
private TextureView textureView;
private TextView textView;
public View onCreateView(LayoutInflater layoutInflater, @Nullable ViewGroup contatiner, Bundle savedInstanceState) {
rootView = layoutInflater.inflate(R.layout.external_display, contatiner, false);
textureView = rootView.findViewById(R.id.camera_view);
textView = rootView.findViewById(R.id.test_text);
return rootView;
}
}
活动中:
private MyFragment myFragment;
private TextureView textureView;
private SurfaceTexture surfaceTexture;
在 onCreate 中:
myFragment =(myFragment)getFragmentManager().findFragmentById(R.id.external_display);
View view = myFragment.getView();
textureView = view.findViewById(R.id.camera_preview);
surfaceTexture = textureView.getSurfaceTexture();
getView() 空对象引用。
【问题讨论】:
-
你可以在这里添加你尝试过的代码sn-p...
-
我添加了一些代码。
标签: android android-fragments android-camera