1
我必須讓用戶選擇在我的應用程序中捕捉視頻,但我不希望預覽出現(或佔用一個空間),當視頻不記錄時。如何取消FragmentTransaction承諾
因此,我使用FragmentTransaction
基於camera2video谷歌示例構建了一個浮動預覽。
我的類變量是:
FragmentTransaction fm = null;
Camera2VideoFragment camera2VideoFragment;
我創建一個實例,並在OnCreate
方法初始化相機:
camera2VideoFragment = Camera2VideoFragment.newInstance();
if (null == savedInstanceState) {
fm = getFragmentManager().beginTransaction()
.replace(R.id.container, camera2VideoFragment);
}
我想用菜單來分享範圍和隱藏預覽(片段)方法(onOptionsItemSelected):
case R.id.action_captureScreen:
item.setChecked(!item.isChecked());
if (item.isChecked())
{
fm.commit(); // show the preview - working
// camera2VideoFragment.captureVideo(); // start capture video
}
else
{
//camera2VideoFragment.captureVideo(); // stop the video and save to file
fm.detach(camera2VideoFragment); // hide the preview - NOT WORKING
}
我也試過fm.hide(camera2VideoFragment)
但它不工作。
那麼,問題是我該如何隱藏\顯示預覽? 謝謝!
非常感謝您! – AsfK