【发布时间】:2016-07-28 21:13:00
【问题描述】:
我有一个按钮,按下该按钮会将 MainActivity 更改为包含相机预览和进度条的 CameraActivity。但是,在活动切换之前,进度条会出现,因此您最终会在 MainActivity 上看到进度条一瞬间。这可能是什么原因造成的?谢谢
这是一些相关的代码。
MainActivity.java
public void openCamera(View view) {
if (getCameraInstance() == null) {
Toast.makeText(FeedActivity.this, "Camera is unavailable right now", Toast.LENGTH_LONG).show();
} else {
Intent i = new Intent(MainActivity.this, CameraActivity.class);
startActivity(i);
}
}
CameraActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
getSupportActionBar().hide();
progressBar = (ProgressBar) findViewById(R.id.progressBar);
animation = ObjectAnimator.ofInt(progressBar, "progress", 0, 100);
animation.setDuration(10000);
animation.setInterpolator(new LinearInterpolator());
// Create an instance of Camera
mCamera = getCameraInstance();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera, currentCameraId);
preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
}
/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
Camera c = null;
try {
c = Camera.open(); // attempt to get a Camera instance
}
catch (Exception e){
// Camera is not available (in use or does not exist)
}
return c; // returns null if camera is unavailable
}
【问题讨论】:
标签: android android-intent android-camera