添加按钮使相机预览不显示

Adding button makes camera preview not display

我有一个具有相机预览视图的应用程序。我添加了一个按钮,它覆盖了相机预览所在的 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();
}

是添加按钮导致的吗?还是其他原因?

yourbutton.setonclickListener(this);

替换

if(v == buttonFreeze) {

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