Zbar相机没有全屏显示

时间:2014-12-10 19:14:25

标签: android zbar

我想使用Zbar自定义布局来扫描条形码。

问题:

正如你所看到的那样,相机没有采用整个画面布局。它取的是宽度,而不是高度。为什么会发生这种情况?

enter image description here

代码:

qrscannerzbarlayout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/zbar_layout_area"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView 
             android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello"
            />
    </LinearLayout>

    <FrameLayout
        android:id="@+id/frmQr"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/ll_footerx"
        android:layout_below="@+id/zbar_layout_area"
        android:layout_centerHorizontal="true" >
    </FrameLayout>

    <RelativeLayout
        android:id="@+id/ll_footerx"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="5dp" >

        <TextView
            android:id="@+id/tv_line123"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="Place barcode in screen view and hold steady"
            android:textSize="14sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/button_back"
            android:layout_width="100dp"
            android:layout_height="48dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/tv_line123"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/trailsky"
            android:text="WONT SCAN" />

        <Button
            android:id="@+id/button_nobarcode"
            android:layout_width="100dp"
            android:layout_height="48dp"
            android:layout_alignParentRight="true"
            android:layout_below="@id/tv_line123"
            android:layout_marginRight="40dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/passyellow"
            android:text="NO BARCODE" />
    </RelativeLayout>

</RelativeLayout>

线性布局用于放置标题,框架布局以放置相机预览以及相对布局以放置页脚。

这是java代码:(我只是复制它的一部分)

public class ZBarScannerActivity extends Activity implements Camera.PreviewCallback, ZBarConstants{
    Button btnnobarcode;

     @SuppressWarnings("unused")
    private static final String TAG = "ZBarScannerActivity";
        private CameraPreview mPreview;
        private Camera mCamera;
        private ImageScanner mScanner;
        private Handler mAutoFocusHandler;
        private boolean mPreviewing = true;

        static {
            System.loadLibrary("iconv");
        }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);


        if(!isCameraAvailable()) {
            // Cancel request if there is no rear-facing camera.
            cancelRequest();
            return;
        }

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.qrscannerzbar_layout);
        btnnobarcode=(Button)findViewById(R.id.button_nobarcode);

        btnnobarcode.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i = new Intent(ZBarScannerActivity.this,AddCardDetails.class);
                i.putExtra("result","");
                startActivity(i);
                finish();
            }
        });

        mAutoFocusHandler = new Handler();

        // Create and configure the ImageScanner;
        setupScanner();

        // Create a RelativeLayout container that will hold a SurfaceView,
        // and set it as the content of our activity.
        mPreview = new CameraPreview(this, this, autoFocusCB);
        //setContentView(mPreview);


        FrameLayout zbarLayout = ( FrameLayout) findViewById(R.id.frmQr);
        mPreview.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        zbarLayout.addView(mPreview);
      }

0 个答案:

没有答案
相关问题