[英]Having overlay in Android Camera Preview
我想在相機預覽中實現如下圖所示的覆蓋。
我的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 ,則執行代碼后不會在相機預覽中顯示它。 知道在相機預覽中如何有這樣的疊加嗎?
我在我的應用程序的相機預覽上方添加了一個按鈕。 我找到了避免完全使用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;
}
我開發的應用程序也遇到了同樣的問題。 我需要相機預覽上的按鈕。 我所做的只是在xml布局中,在所需的任何View項上-只需添加屬性
android:alpha"0.5"
0.5是50%透明
祝好運
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.