How to make full size view when using TextureView in android?

5.2k views Asked by At

I have developed a camera app using ,latest Camera 2 API,the camera preview is set to a Texture view, I set both width and height as Match_parent ,is there any other attributes needed to set ?how can I set the camera preview in a full screen view??I am a beginner, I don't know how to set this,can anybody help??

   <TextureView
        android:id="@+id/texture"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

         />

This is the screen shot of my screen,I want to make it full screen

3

There are 3 answers

2
Mike On

Use a NoActionBar Theme for that activity. This answer can guide you to achieve that.

0
Trung NT Nguyen On

Please use DisplayMetrics to get w/h you want

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
RelativeLayout preview_video_parent = (RelativeLayout) findViewById(R.id.preview_video_parent);
LayoutParams layoutParams = (LayoutParams) preview_video_parent
    .getLayoutParams();
layoutParams.width = displaymetrics.widthPixels;
layoutParams.height = displaymetrics.heightPixels;
mTextureView.setLayoutParams(layoutParams);
0
Gabriella Angelova On

maybe this could be useful for you : get the camera sizes and set them to the texturuView like this:

Camera mCamera = Camera.open();
Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
TextureView myTexture = (TextureView)findViewById(R.id.texture); 
myTexture.setLayoutParams(new FrameLayout.LayoutParams(previewSize.width, previewSize.height, Gravity.CENTER));

Here you could take a look at a complete example http://www.tutorialspoint.com/android/android_textureview.htm