Я просматриваю код, чтобы отобразить пользовательский вид (кружок) на предварительном просмотре камеры. Он строит отлично без ошибок, но проблема в том, что пользовательский вид не отображается. Возможно, я ошибаюсь в интеграции пользовательского представления в главной операции или в XML, но не могу понять это. Нужно мнение экспертов о том, что, спасибоПользовательский макет не отображается вообще - Android
Основная деятельность - Запуск камеры и интегрировать пользовательский вид на него
public class AndroidVideoCaptureExample extends Activity {
private Context myContext;
private FrameLayout cameraPreview;
private boolean cameraFront = false;
private int desiredwidth=640, desiredheight=360;
private MyDrawing md;
@Override
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();
}
}
CustomView класса - Чтобы нарисовать круг на камеры предварительного просмотра
public class MyDrawing extends View {
Canvas canvas;
private static final int DEFAULT_CIRCLE_COLOR = Color.RED;
private int circleColor = DEFAULT_CIRCLE_COLOR;
private Paint paint;
public MyDrawing(Context context) {
super(context);
init(context, null);
}
public MyDrawing(Context context, AttributeSet attrs)
{
super(context, attrs);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs)
{
paint = new Paint();
paint.setAntiAlias(true);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
int w = getWidth()/2;
int h = getHeight()/2;
int pl = getPaddingLeft();
int pr = getPaddingRight();
int pt = getPaddingTop();
int pb = getPaddingBottom();
int usableWidth = w - (pl + pr);
int usableHeight = h - (pt + pb);
int radius = Math.min(usableWidth, usableHeight)/2;
int cx = pl + (usableWidth/2);
int cy = pt + (usableHeight/2);
paint.setColor(circleColor);
canvas.drawCircle(cx, cy, radius, paint);
}
}
Layout XML - Предварительный обзор камеры с пользовательским просмотром на нем
<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: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="match_parent"
android:layout_height="534dp"
android:orientation="horizontal"
/>
</FrameLayout>
</FrameLayout>
Круг нарисованный имеет половину ширины холста. где я должен поставить Measure() и почему. can u plz уточнить –
, пожалуйста, см. мое редактирование –
Позволит вам знать, как только я попробую. Надеюсь, что это решение –