我的相机预览中未显示自定义视图。无法弄清楚原因。代码运行正常,只有圆圈没有画上它。也搜索了它,但还没有帮助。
主要类
<select is="my-select">
<option value="1">1</option>
<option value="2">2</option>
<select>
}
XML类
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
md = (MyDrawing)findViewById(R.id.Drawing);
myContext = this;
initialize();
}
自定义视图
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<FrameLayout
android:orientation="vertical"
android:layout_width="404dp"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom">
<Button
android:id="@+id/button_capture"
android:layout_width="348dp"
android:layout_height="wrap_content"
android:text="Capture/Stop"
android:layout_gravity="center_horizontal|bottom"
/>
</FrameLayout>
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="504dp"
android:orientation="horizontal">
<com.javacodegeeks.androidvideocaptureexample.MyDrawing
android:id="@+id/Drawing"
android:layout_width="192dp"
android:layout_height="200dp"
android:orientation="horizontal"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
答案 0 :(得分:0)
请替换
private void onMeasure()
{
w = getWidth()/2;
h = getHeight()/2;
}
与
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
w = getWidth()/2;
h = getHeight()/2;
}
答案 1 :(得分:0)
图层顺序是我所缺少的。刚刚使用了相对布局,并在主要活动代码中也进行了更改。结果是“EUREKA”!
<?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:orientation="horizontal"
android:baselineAligned="false">
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="303dp"
android:layout_height="470dp"
android:orientation="horizontal"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/Drawing">
</FrameLayout>
<Button
android:id="@+id/button_capture"
android:layout_width="393dp"
android:layout_height="92dp"
android:text="Capture/Stop"
android:layout_gravity="center_horizontal|bottom"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<com.javacodegeeks.androidvideocaptureexample.MyDrawing
android:id="@+id/Drawing"
android:layout_width="500dp"
android:layout_height="507dp"
android:orientation="horizontal"
android:layout_alignParentTop="true"
/>
</RelativeLayout>