【问题标题】:How should I add elements to a custom camera android application?我应该如何向自定义相机 Android 应用程序添加元素?
【发布时间】:2013-07-29 19:54:13
【问题描述】:

我的 android 应用使用自定义相机。我的 xml 布局文件中只有一个框架布局(全屏),我以编程方式向其中添加了一个包含相机预览的表面视图。

现在我想在我的框架布局中添加一些按钮。我知道我可以通过编程方式添加这些按钮,但有没有更好的方法来做到这一点。我的意思是,我是否可以创建一个类似于蒙版/布局的东西,其中包含一些按钮,然后我以编程方式将其添加到我的框架布局中?

专业应用开发者如何做到这一点?我只是想知道这一切,这样我才能保持一个好的设计。

非常感谢!

【问题讨论】:

    标签: android camera android-linearlayout android-framelayout


    【解决方案1】:
    【解决方案2】:

    创建您的布局 xml 文件。根据您提供的信息,基地将是FrameLayout。将按钮和其他小部件放置在您需要的任何位置。例如,假设您在 FrameLayout 中放置了 3 个按钮:b1、b2 和 b3。

    添加SurfaceView 后,按钮将不可见。这样做可以在 SurfaceView 上显示它们:

    // Initially
    
    frameLayout = (FrameLayout) findViewById(R.id.framelayout_id_from_xml_file);
    
    b1 = (Button) findViewById(R.id.button_id_from_xml_file_1);
    
    b2 = (Button) findViewById(R.id.button_id_from_xml_file_2);
    
    b3 = (Button) findViewById(R.id.button_id_from_xml_file_3);
    
    ....
    ....
    ....
    
    // create a SurfaceView and add it to the framelayout
    
    frameLayout.add(sufaceView);
    
    // now, remove the buttons and add them again
    
    frameLayout.removeView(b1);
    frameLayout.addView(b1);
    
    frameLayout.removeView(b2);
    frameLayout.addView(b2);
    
    frameLayout.removeView(b3);
    frameLayout.addView(b3);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      • 2019-04-19
      • 2012-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多