【问题标题】:Adding button makes camera preview not display添加按钮使相机预览不显示
【发布时间】:2015-06-03 03:00:03
【问题描述】:

我有一个具有相机预览视图的应用。我添加了一个按钮,该按钮覆盖了相机预览所在的 FrameLayout。在我添加按钮之前,相机预览工作正常;但是,添加按钮后,相机预览不显示。

这是我正在使用的 xml 布局:

    >
</FrameLayout>
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|bottom"
    >
<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Freeze"
        android:id="@+id/buttonFreeze"
        android:background="@null"
        android:clickable="true" />
</LinearLayout>

我的 onClick 监听器和对应的方法:

public void onClick(View v) {
    if(v == buttonFreeze) {
        if(buttonFreeze.getText().equals("Freeze")) {
            mirrorView.freezePreview();
            buttonFreeze.setText("Unfreeze");
        } else {
            mirrorView.unfreezePreview();
            buttonFreeze.setText("Freeze");
        }
    }

}

public void freezePreview() {
    mCamera.stopPreview();
}

public void unfreezePreview() {
    mCamera.startPreview();
}

是按钮的添加导致了这种情况吗?还是别的什么?

【问题讨论】:

  • 为什么使用LinearLayout?评论它并将按钮放在底部|水平
  • 将线性布局放入框架布局并设置重力底部。正确显示您的xml,

标签: android android-layout android-camera


【解决方案1】:

替换

if(v == buttonFreeze) {

if(v.getId() == R.id.buttonFreeze) {

【讨论】:

    【解决方案2】:

    yourbutton.setonclickListener(this);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多