我想在相机预览中实现如下图所示的叠加效果。
我的xml看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="399dp" >
</FrameLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/camera_preview"
android:layout_marginLeft="35dp"
android:text="@string/share" />
<Button
android:id="@+id/button_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/button1"
android:layout_marginRight="38dp"
android:text="@string/capture" />
</RelativeLayout>
如果我尝试在 framelayout 中使用 listview ,则在执行我的代码后,它不会显示相机预览。任何想法如何在相机预览中有这样的叠加?
答案 0 :(得分:0)
我在我的应用的相机预览顶部添加了一个按钮。我找到了完全避免使用XML并且只是编程的解决方案。这可能对您有用。
相机类扩展了Fragment。但是你可以在这里看到按钮被创建然后被添加到视图中。在相机表面视图之后。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.camera_fragment,
container, false);
myCamera = getCameraInstance();
recording = false;
if (myCamera == null) {
Toast.makeText(getActivity(), "Fail to get Camera",
Toast.LENGTH_LONG).show();
}
Button button = new Button(getActivity());
//button.setBackgroundResource(R.drawable.record);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.width = 260;
params.height = 260;
button.setLayoutParams(params);
button.setText("Record");
myCameraSurfaceView = new GetCamera(getActivity(), myCamera);
((ViewGroup) rootView).addView(myCameraSurfaceView);
((ViewGroup) rootView).addView(button);
button.setOnClickListener(this);
return rootView;
}
答案 1 :(得分:0)
我开发的应用程序遇到了同样的问题。我在相机预览上需要按钮。 我所做的就是在xml布局中,在你想要的任何View项目上 - 只需添加属性
android:alpha"0.5"
其中0.5是50%透明
祝你好运