6

我正在尝试创建一个布局,该布局在顶部包含一个“SurfaceView”,其水平工具栏在底部分为 3 个部分,但是包含相机预览的 SurfaceView 只是唯一显示的元素。请指出我的布局 xml 中的错误或提供类似的布局 xml,谢谢。

以下是我根据用户推荐的布局和更新

尝试#1(RelativeLayout 作为根):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LayoutForPreview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:screenOrientation="portrait" >

    <SurfaceView
        android:id="@+id/surfaceViewBarcodeScanner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayoutToolbar"
        android:layout_gravity="top"
        android:scaleType="fitXY" />

    <LinearLayout
        android:id="@+id/linearLayoutToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_left" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.68"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_center_toolbar" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_right_landscape_button" />
    </LinearLayout>

</RelativeLayout>

下面是我想要的 GUI 外观:

在此处输入图像描述

尝试 #1 结果,设备快照,仅显示 SurfaceView:

在此处输入图像描述

eclipse GUI 工具的快照,它显示了布局应该是什么样子。 在此处输入图像描述

尝试 #2(LinearLayout 作为根):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LayoutForPreview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:screenOrientation="portrait" >

    <SurfaceView
        android:id="@+id/surfaceViewBarcodeScanner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:scaleType="fitXY"
        android:layout_weight="1" />

    <LinearLayout
        android:id="@+id/linearLayoutToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="bottom" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_left" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.68"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_center_toolbar" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_right_landscape_button" />
    </LinearLayout>

</LinearLayout>

尝试#2,结果,设备快照:

在此处输入图像描述

问题:

1) 工具栏出现在顶部而不是底部

2)相机预览冻结和应用程序崩溃。由于某种原因 LinearLayout 导致相机错误 1001 ,我认为它与预览尺寸有关。

尝试 #3(以编程方式将工具栏添加到活动 onCreate 中的相对或线性布局)。

线性布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LayoutForPreview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:screenOrientation="portrait" >

    <SurfaceView
        android:id="@+id/surfaceViewBarcodeScanner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:scaleType="fitXY"
        android:layout_weight="1" />

</LinearLayout>

稍后通过 Java 代码添加的单独 XML 中定义的工具栏:

<?xml version="1.0" encoding="UTF-8"?>
<!--  LinearLayout that contains toolbar that is divided into 3 sections horizontally , layout_below="@+id/BarcodeScannerFrame-->
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayoutToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_left" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.68"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_center_toolbar" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>

onCreate,onResume,仅我活动的其他相关代码片段,LinearLayout 工具栏在运行时添加到线性或相对布局:

//import not included 
    public class ScanVinFromBarcodeActivity extends Activity {
        // camera object that is used globally in this activity and also passed
        // reference to PreviewSurface inner class
        private Camera globalCamera;
        private int cameraId = 0;
        // bitmap that would created after picture is taken and converted from
        // camera bytes
        private Bitmap bmpOfTheImageFromCamera = null;
        // global flag whether a camera has been detected
        private boolean isThereACamera = false;
        // layout for this activity
        private LinearLayout RelativeLayoutBarcodeScanner= null;
        // CameraPreview extends SurfaceView displays preview of images from the
        // Camera
        private CameraPreview newCameraPreview = null;
        // used to inflate the xml layout
        private SurfaceView surfaceViewBarcodeScanner = null;
        private boolean cameraPreviewing = false;
        // this continueToAutomaticallyDecode flag is initially set to TRUE, but
        // will be set to FALSE on the first successful decode OR when a crucial
        // method in the code process fails or throws an exception
        private volatile boolean continueToAutomaticallyDecode = true;
        // global flag used to indicate picture taking & decoding is in progress
        private volatile boolean takingPictureAndDecodeInprogress = false;
        // Bitmap options for bitmap creation from camera picture
        BitmapFactory.Options options = null;
        // used for samsung galaxy s devices only
        private Matrix rotationMatrix90CounterClockWise = null;
        // Reader is class from zxing used to decode barcodes
        Reader reader = null;
        // DecodeHintType hashtable is used to provide help to the zxing Reader
        // class
        Hashtable<DecodeHintType, Object> decodeHints = null;
        //
        private boolean onTouchEvent = true;
        //
        private OrientationEventListener orientationEventListener = null;
        // 1 means the screen is PORTRAIT and 2 means screen is LANDSCAPE
        private int latestScreenOrientation = 1;
        //
        Camera.Parameters Flash = null;
        //
        private String globalVIN = null; 
        //
        private Handler handler = null;
        //
        private LinearLayout barcodeVinScannerToolbar = null; 

        public boolean isContinueToAutomaticallyDecode() {

            return continueToAutomaticallyDecode;
        }

        public void setContinueToAutomaticallyDecode(
                boolean continueToAutomaticallyDecode) {

                this.continueToAutomaticallyDecode = continueToAutomaticallyDecode;

        }

        public boolean isTakingPictureAndDecodeInprogress() {
            return takingPictureAndDecodeInprogress;
        }

        public void setTakingPictureAndDecodeInprogress(
                boolean takingPictureAndDecodeInprogress) {

                this.takingPictureAndDecodeInprogress = takingPictureAndDecodeInprogress;

        }

        /*
         * This method , finds FEATURE_CAMERA, opens the camera, set parameters ,
         * add CameraPreview to layout, set camera surface holder, start preview
         */
        @SuppressLint("InlinedApi")
        private void initializeGlobalCamera() {

            try {
                if (!getPackageManager().hasSystemFeature(
                        PackageManager.FEATURE_CAMERA)) {
                    Toast.makeText(this, "No camera on this device",
                            Toast.LENGTH_LONG).show();
                } else { // check for front camera ,and get the ID
                    cameraId = findFrontFacingCamera();
                    if (cameraId < 0) {

                        Toast.makeText(this, "No front facing camera found.",
                                Toast.LENGTH_LONG).show();
                    } else {

                        Log.d("ClassScanViewBarcodeActivity",
                                "camera was found , ID: " + cameraId);
                        // camera was found , set global camera flag to true
                        isThereACamera = true;
                        // OPEN
                        globalCamera = getGlobalCamera(cameraId);
                        // parameters auto focus
                        globalCamera.getParameters().setFocusMode(
                                Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                        // set picture format to JPEG, everytime makesure JPEg
                        globalCamera.getParameters().setPictureFormat(
                                ImageFormat.JPEG);
                        autoFocusSetupForBarcode(globalCamera);
                        /*
                         * START early setup variables & setting used in
                         * jpegCallback in order to optimize the jpegCallback code
                         */
                        options = new BitmapFactory.Options();
                        // option set for down sampling he captured image taken from
                        // the camera in order to MemoryOutOfBounds exception
                        options.inSampleSize = 4;
                        // image quality rather than speed in order to achieve early
                        // barcode detection & decode
                        options.inPreferQualityOverSpeed = false;
                        // Samsung galaxy S only , rotate to correct orientation
                        // ,and capture only the image within the guidance rectangle

                        rotationMatrix90CounterClockWise = new Matrix();
                        rotationMatrix90CounterClockWise.postRotate(90);
                        // early variable used by zxing to decode method
                        decodeHints = new Hashtable<DecodeHintType, Object>();
                        decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
                        decodeHints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
                        decodeHints.put(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT,
                                Boolean.TRUE);
                        reader = new MultiFormatReader();

                        turnOnFlashlight(globalCamera);

                        // pass surfaceView to CameraPreview
                        newCameraPreview = new CameraPreview(this, globalCamera) {

                            @Override
                            public boolean onTouchEvent(MotionEvent event) {
                                Log.d("ClassScanViewBarcodeActivity",
                                        " onTouchEvent(MotionEvent event) ");

                                onTouchEvent = true;
                                globalCamera
                                        .autoFocus(autoFocusCallbackForAutomaticScan);

                                return super.onTouchEvent(event);
                            }

                        };

                        // pass CameraPreview to Layout
                        RelativeLayoutBarcodeScanner.addView(newCameraPreview);


                        // give reference SurfaceView to camera object
                        globalCamera.setPreviewDisplay(surfaceViewBarcodeScanner
                                .getHolder());

                        // PREVIEW
                        if (cameraPreviewing != true) {
                            globalCamera.startPreview();
                        }

                        Log.d("ClassScanViewBarcodeActivity",
                                "camera opened & previewing");
                    }
                }// end else ,check for front camera
            }// end try
            catch (Exception exc) {

                // in case of exception release resources & cleanup
                if (globalCamera != null) {
                    globalCamera.stopPreview();
                    cameraPreviewing = false;
                    globalCamera.setPreviewCallback(null);
                    globalCamera.release();
                    globalCamera = null;
                    options = null;
                    rotationMatrix90CounterClockWise = null;
                    reader = null;

                }
                Log.d("ClassScanViewBarcodeActivity initializeGlobalCamera() exception:",
                        exc.getMessage());
                exc.printStackTrace();
            }// end catch

        }// end ini

        /* this method detect whether the camera flashlight a.k.a torch feature is available to be turned on then turns on the light*/
        public void turnOnFlashlight(Camera camera) {
            Log.d("ClassScanViewBarcodeActivity",
                    "turnOnFlashlight(Camera camera )");

            boolean flag = false;
            Context context  = null; 
            if (camera != null) {
                Log.d("ClassScanViewBarcodeActivity",
                        "turnOnFlashlight() , FEATURE_CAMERA_FLASH: " + flag);

                context = RelativeLayoutBarcodeScanner.getContext();
                if (context != null) {
                    flag = context.getPackageManager().hasSystemFeature(
                            PackageManager.FEATURE_CAMERA_FLASH);
                    if (flag) {
                        Flash = camera.getParameters();
                        Flash.setFlashMode("torch");

                        camera.setParameters(Flash);

                    }// end if camera feature is available

                    else {
                        Log.d("ClassScanViewBarcodeActivity",
                                "turnOnFlashlight() , FEATURE_CAMERA_FLASH: "
                                        + flag);
                    }
                }// end if context not null

            }// end camera not null

        }// end turnOnFlashlight(Camera camera )

        // onCreate, instantiates layouts & surfaceView used for video preview
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_barcode_vin_scanner);
            Log.d("ClassScanViewBarcodeActivity", "onCreate ");

            // create surfaceView for previewing of camera image
            RelativeLayoutBarcodeScanner = (LinearLayout) findViewById(R.id.LayoutForPreview);
            surfaceViewBarcodeScanner = (SurfaceView) findViewById(R.id.surfaceViewBarcodeScanner);
            barcodeVinScannerToolbar = (LinearLayout) findViewById(R.id.linearLayoutToolbar);



            initializeGlobalCamera();


            //*****TOOLBAR IS ADDED*****

            if (RelativeLayoutBarcodeScanner!=null && barcodeVinScannerToolbar!=null)
            {

                //surfaceViewBarcodeScanner.addChildrenForAccessibility(list);
               RelativeLayoutBarcodeScanner.addView(barcodeVinScannerToolbar);      

            }


            // instantiate orientationEventListener
            orientationEventListener = new OrientationEventListener(this,
                    SensorManager.SENSOR_DELAY_NORMAL) {

                @Override
                public void onOrientationChanged(int arg0) {


                    /*
                    latestScreenOrientation = ScreenUtility
                            .getScreenOrientation(RelativeLayoutBarcodeScanner.getContext());

                    Log.d("ClassScanViewBarcodeActivity",
                            "latestScreenOrientation: " + latestScreenOrientation);

                    if (orientationEventListener.canDetectOrientation()) {
                        orientationEventListener.enable();
                        Log.d("ClassScanViewBarcodeActivity",
                                "enabled orientationEventListener: "
                                        + String.valueOf(orientationEventListener
                                                .canDetectOrientation()));
                    } else {
                        Log.d("ClassScanViewBarcodeActivity",
                                "enabled orientationEventListener: "
                                        + String.valueOf(orientationEventListener
                                                .canDetectOrientation()));
                    }
    */
                }

            };



            handler = new Handler();




        }// end onCreate


        @Override
        protected void onResume() {

            Log.d("ClassScanViewBarcodeActivity, onResume() globalCamera:",
                    String.valueOf(globalCamera));

            initializeGlobalCamera();


            //*****TOOLBAR IS ADDED*****

            if (RelativeLayoutBarcodeScanner!=null && barcodeVinScannerToolbar!=null)
            {

                //surfaceViewBarcodeScanner.addChildrenForAccessibility(list);
               RelativeLayoutBarcodeScanner.addView(barcodeVinScannerToolbar);      

            }


            if (orientationEventListener != null) {
                orientationEventListener.enable();
            }

            super.onResume();
        }

        @Override
        protected void onStop() {

            if (globalCamera != null) {
                globalCamera.stopPreview();
                cameraPreviewing = false;
                globalCamera.setPreviewCallback(null);
                globalCamera.release();
                globalCamera = null;
            }

            if (orientationEventListener != null) {
                orientationEventListener.disable();
            }
            super.onStop();
        }

        @Override
        protected void onPause() {
            if (globalCamera != null) {
                globalCamera.stopPreview();
                cameraPreviewing = false;
                globalCamera.setPreviewCallback(null);
                globalCamera.release();
                globalCamera = null;
                options = null;
                rotationMatrix90CounterClockWise = null;
                reader = null;
            }
            if (orientationEventListener != null) {
                orientationEventListener.disable();
            }
            super.onPause();
        }// end onPause()

    //other irrelevant code was not included

    }//end activity

尝试 #3,结果,屏幕冻结,未报告特定错误或异常:

在此处输入图像描述

错误日志:

在此处输入图像描述

**如果 eclipse GUI 工具显示所需的外观,那为什么工具栏仍然丢失???我想在底部有工具栏,最好使用 RelativeLayout 没有任何崩溃或屏幕冻结。任何帮助将不胜感激。

我正在使用三星 Galaxy S3 进行测试。

谢谢。**

4

9 回答 9

1

你想要这样的东西吗?

在此处输入图像描述

我使用的布局是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <LinearLayout
        android:id="@+id/linearLayoutToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        >
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:src="@drawable/ic_launcher"
        />
        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:src="@drawable/ic_launcher"
        />
        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:src="@drawable/ic_launcher"
        />
    </LinearLayout>
    <SurfaceView
        android:id="@+id/surfaceViewBarcodeScanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/linearLayoutToolbar"
    />
</RelativeLayout>

请注意,由于我的 res/drawable 文件夹中没有您的图像,因此我将它们替换为ic_launcher

另请注意,我使用了运行Froyo(API 级别 2.2)的ldpi设备。这就是为什么图像比你的小,用户界面略有不同(...)。无论如何,它适用于每个分辨率和每个操作系统版本

于 2013-12-05T17:04:22.817 回答
0

您真正想要的不是使用 Relativelayout,而是使用 Linearlayout 作为您的根。然后将surfaceview权重设置为1,类似于:

 <SurfaceView
    android:id="@+id/surfaceViewBarcodeScanner"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"/>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scanner_bottom_left" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scanner_bottom_center_toolbar" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>

于 2013-11-23T18:37:02.383 回答
0

你忘了告诉surfaceView是。您的代码需要与此类似:abovelinearLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linearLayoutToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/scanner_bottom_left" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/scanner_bottom_center_toolbar" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/scanner_bottom_right_landscape_button" />
    </LinearLayout>

    <SurfaceView
        android:id="@+id/surfaceViewBarcodeScanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/linearLayoutToolbar" />

</RelativeLayout>
于 2013-11-23T19:44:57.850 回答
0

我在您的初始 XML 1 中看到了一些错误。在您使用的表面视图中:

android:layout_above="@+id/linearLayoutToolbar"

您应该在创建 Id 时使用 @+id,但是当您想要引用时,您应该只使用 @id 像这样:

android:layout_above="@id/linearLayoutToolbar"

2. 你不能引用另一个尚未创建的对象!所以你应该把surfaceview放在de linearlayout下面,如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LayoutForPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:screenOrientation="portrait" >

<LinearLayout
    android:id="@+id/linearLayoutToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_left" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.68"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_center_toolbar" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>

<SurfaceView
    android:id="@+id/surfaceViewBarcodeScanner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/linearLayoutToolbar"
    android:layout_gravity="top"
    android:scaleType="fitXY" />

</RelativeLayout>

3. 你应该像这样为你的 3 个 ImageViews 添加权重:

android:layout_weight="1"
于 2013-12-05T08:31:30.187 回答
0

初始布局中的一些小更改将导致消除错误。您需要使用android:layout_height="0dp",定义 0dp 将帮助您的表面视图适合您的屏幕。

<SurfaceView
    android:id="@+id/surfaceViewBarcodeScanner"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_above="@+id/linearLayoutToolbar"
    />

而且我没有在 SurfaceView 中找到使用以下属性。

    android:layout_gravity="top" 
    android:scaleType="fitXY"

查看此布局设计、android:layout_height="0dp" 的工作原理以及android:layout_width="0dp" 的工作原理。

于 2013-12-06T06:46:11.147 回答
0

尝试将布局更改为:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LayoutForPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:screenOrientation="portrait" >

<SurfaceView
    android:id="@+id/surfaceViewBarcodeScanner"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_gravity="top"
    android:scaleType="fitXY"
    android:layout_weight="1" />

<LinearLayout
    android:id="@+id/linearLayoutToolbar"
    android:layout_width="match_parent"
    android:layout_height="0dp"
     android:layout_weight=".1"
    android:orientation="horizontal"
    android:layout_gravity="bottom" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_left" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.68"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_center_toolbar" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>

于 2013-12-04T04:16:35.430 回答
0

我在许多应用程序中都使用过这种布局,这就是你的布局。没有花招,没有祈求好运,这只是实现它的干净、快乐和始终如一的方式

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

    <SurfaceView
        android:id="@+id/surfaceViewBarcodeScanner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayoutToolbar"
        android:layout_alignParentTop="true" />

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayoutToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_left" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.68"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_center_toolbar" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/scanner_bottom_right_landscape_button" />
    </LinearLayout>

</RelativeLayout>

在这里,您可以预览我的一个应用程序。

发布的代码适用于您的代码,因此复制/粘贴即可。请注意,它的所有内容都在一个简单的文件中,因此您必须稍微更改您的活动

于 2013-12-06T10:10:46.533 回答
0

将此添加到您的LinearLayout容器中imageView

 android:layout_alignParentBottom="true"
于 2013-11-23T18:17:18.613 回答
0

为什么使用 RelativeLayout 作为根布局,我认为在其中一个子视图中使用带有 layout_weight 参数的 LinearLayou 更简单:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">


<SurfaceView
    android:layout_weight="1"
    android:id="@+id/surfaceViewBarcodeScanner"
    android:layout_width="match_parent"
    android:layout_height="0dp" />

<!--  LinearLayout that contains toolbar that is divided into 3 sections horizontally -->
<LinearLayout
    android:id="@+id/linearLayoutToolbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scanner_bottom_left" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scanner_bottom_center_toolbar" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</LinearLayout>
于 2013-11-24T15:23:13.910 回答