【问题标题】:Add view to a FrameLayout "invisibly"“隐形”将视图添加到 FrameLayout
【发布时间】:2012-11-27 21:54:31
【问题描述】:

我正在设置一个具有两个视图的框架布局 - 一个是 ImageView,另一个是相机预览。代码如下:

public void setUpCamera(){
    //Set cameraView as the camera preview class
    cameraView = new CameraPreview(getApplicationContext());
    //Set imageResult as an image
    imageResult = new ImageView(getApplicationContext());

    imageResult.setBackgroundColor(Color.GRAY);

    //Prime the frame and buttons from the xml file
    frameLayout = (FrameLayout) findViewById(R.id.camera_preview);
    snapPhoto = (Button) findViewById(R.id.button_capture);

    //Add both camera preview and the snapped picture to the FrameLayout in the xml file 
    frameLayout.addView(imageResult);
    frameLayout.addView(cameraView);

    frameLayout.bringChildToFront(imageResult);

现在我的问题是是否可以将 cameraView “隐形”添加到 FrameLayout?这是一件小事,但否则在设置相机时,您会在通过bringChildToFront 方法突出显示图像之前获得相机预览模式的闪光。

任何想法将不胜感激!

【问题讨论】:

    标签: android android-layout android-camera


    【解决方案1】:

    你是setVisibility(View.GONE)还是setVisibility(View.INVISIBLE)

    GONE 调整您的布局,就好像视图没有完全丢失一样,INVISIBLE 保持任何间距。

    【讨论】:

    • 太棒了,这正是我正在寻找的方法。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    相关资源
    最近更新 更多