How to programmatically control Preview size of Android camera app

Tomoaki Imai
5 min readFeb 20, 2020

It’s been a while since I posted an article about how we take a photo using Camera2 API. Today I’m going to share the way to control the screen size of the preview.

First, let me go through the necessary steps to configure the preview screen. Then I will explain two camera app examples — the first one is a full-screen preview and the other one with the preview which fits the width of a screen.

Switching between full-size and width match preview

If you want to peek the code first, here’s a link to it:

Step by step guide to understand how to configure the preview screen

We configure the preview size right after Camera Manager is instantiated and SurfaceTexture, where the preview gets rendered, is ready.

--

--

Tomoaki Imai
Tomoaki Imai

Written by Tomoaki Imai

CTO at Noxx https://www.noxx.net/ AI hiring tool. FullStack developer and leader. Love to share ideas about software development. https://github.com/tomoima525

Responses (2)