title: Android - how to change barcode scanner view size?
body: <p>I am trying to make Barcode Scanner by following this YouTube <a href="https://www.youtube.com/watch?v=otkz5Cwdw38&amp;t=127s" rel="nofollow noreferrer">video</a>.By following this video I am able to get app working. But as the barcode reader takes the entire page while the scanning cursor takes just around 40% of screen area. So I want to know if there is a way to Shrink the barcode and remaining space can be used to put some buttons or warning TexViews.
  So basically I want to set width and height of QR camera view.So is it possible?</p>
  
  <p><a href="https://i.stack.imgur.com/ddrwn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ddrwn.jpg" alt="enter image description here"></a></p>
  
  <p>As it is clear that space outside of green square is waste and that's why I want to arrange it so that it comes in about 200dp*200dp in dimension.</p>
  
  <p>Code is as follow:</p>
  
  <pre><code>package com.example.priyanka.qrbarcodescanner
  
  import android.content.Context
  import android.content.DialogInterface
  import android.content.Intent
  import android.content.pm.PackageManager
  import android.hardware.Camera
  import android.net.Uri
  import android.os.Build
  import android.support.v4.app.ActivityCompat
  import android.support.v4.content.ContextCompat
  import android.support.v7.app.AlertDialog
  import android.support.v7.app.AppCompatActivity
  import android.os.Bundle
  import android.util.Log
  import android.widget.Toast
  
  import com.google.zxing.Result
  
  import me.dm7.barcodescanner.zxing.ZXingScannerView
  
  import android.Manifest.permission.CAMERA
  
  class MainActivity : AppCompatActivity(), ZXingScannerView.ResultHandler {
      private var scannerView: ZXingScannerView? = null
      internal var mcontext: Context? = null
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          mcontext = this
  
          scannerView = ZXingScannerView(this)
          setContentView(scannerView)
          val currentApiVersion = Build.VERSION.SDK_INT
  
          if (currentApiVersion &gt;= Build.VERSION_CODES.M) {
              if (checkPermission()) {
                  Toast.makeText(applicationContext, "Permission already granted!", Toast.LENGTH_LONG).show()
              } else {
                  requestPermission()
              }
          }
      }
  
      private fun checkPermission(): Boolean {
          return ContextCompat.checkSelfPermission(applicationContext, CAMERA) == PackageManager.PERMISSION_GRANTED
      }
  
      private fun requestPermission() {
          ActivityCompat.requestPermissions(this, arrayOf(CAMERA), REQUEST_CAMERA)
      }
  
      public override fun onResume() {
          super.onResume()
  
          val currentapiVersion = android.os.Build.VERSION.SDK_INT
          if (currentapiVersion &gt;= android.os.Build.VERSION_CODES.M) {
              if (checkPermission()) {
                  if (scannerView == null) {
                      scannerView = ZXingScannerView(this)
                      setContentView(scannerView)
                  }
                  scannerView!!.setResultHandler(this)
                  scannerView!!.startCamera()
              } else {
                  requestPermission()
              }
          }
      }
  
      public override fun onDestroy() {
          super.onDestroy()
          scannerView!!.stopCamera()
      }
  
      override fun onRequestPermissionsResult(requestCode: Int, permissions: Array&lt;String&gt;, grantResults: IntArray) {
          when (requestCode) {
              REQUEST_CAMERA -&gt; if (grantResults.size &gt; 0) {
  
                  val cameraAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED
                  if (cameraAccepted) {
                      Toast.makeText(applicationContext, "Permission Granted, Now you can access camera", Toast.LENGTH_LONG).show()
                  } else {
                      Toast.makeText(applicationContext, "Permission Denied, You cannot access and camera", Toast.LENGTH_LONG).show()
                      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
                          if (shouldShowRequestPermissionRationale(CAMERA)) {
                              showMessageOKCancel("You need to allow access to both the permissions",
                                      DialogInterface.OnClickListener { dialog, which -&gt;
                                          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
                                              requestPermissions(arrayOf(CAMERA),
                                                      REQUEST_CAMERA)
                                          }
                                      })
                              return
                          }
                      }
                  }
              }
          }
      }
  
      private fun showMessageOKCancel(message: String, okListener: DialogInterface.OnClickListener) {
          android.support.v7.app.AlertDialog.Builder(mcontext!!)
                  .setMessage(message)
                  .setPositiveButton("OK", okListener)
                  .setNegativeButton("Cancel", null)
                  .create()
                  .show()
      }
  
      override fun handleResult(result: Result) {
          val myResult = result.text
          Log.d("QRCodeScanner", result.text)
          Log.d("QRCodeScanner", result.barcodeFormat.toString())
  
          val builder = AlertDialog.Builder(this)
          builder.setTitle("Scan Result")
          builder.setPositiveButton("OK") { dialog, which -&gt; scannerView!!.resumeCameraPreview(this@MainActivity) }
          builder.setNeutralButton("Visit") { dialog, which -&gt;
              val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(myResult))
              startActivity(browserIntent)
          }
          builder.setMessage(result.text)
          val alert1 = builder.create()
          alert1.show()
      }
  
      companion object {
  
          private val REQUEST_CAMERA = 1
          private val camId = Camera.CameraInfo.CAMERA_FACING_BACK
      }
  }
  </code></pre>
  
  <p>Thank you in advance.</p>