我有两个习惯viewgroups,superViewGroup和subViewGroup.子视图组包含视图.我将我的superviewgroup添加到linearLayout和subViewGroups我的superviewgroup.
onMeasure()superviewgroup被调用但不在子视图组中.但是在这两种情况下onLayout()方法都被调用了.
代码如下
public class SuperViewGroup extends ViewGroup{
public SuperViewGroup(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Log.i("boxchart","INSIDE ON MEASURE SUPER VIEWGROUP");
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用本机代码中的OpenCV lib(即在Android应用程序的jni文件夹中)绘制一个形状,并调用本机方法将图像返回到Java代码并显示它.
怎么做?我找不到使用OpenCV的Android的简单应用程序.我也设置了环境,使用OpenCV为Android提供的示例如cvcamera,校准运行正常.他们使用SWIG作为JNI接口.SWIG是强制性的吗?我没有使用SWIG.我尝试了很多,我还在努力.
在Java中,代码是这样的:
public class HelloJni extends Activity
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new ShapeView(this));
}
static {
System.loadLibrary("hello-jni");
}
}
class ShapeView extends View
{
private Bitmap mBitmap;
private static native Object drawingShape();
public ShapeView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas) {
mBitmap = (Bitmap) drawingShape();
canvas.drawBitmap(mBitmap, 0, 0, null);
}
}
Run Code Online (Sandbox Code Playgroud)
而在本土jni类中,
#include "ShapeView.h"
#include <string.h>
#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
JNIEXPORT jobject JNICALL Java_ShapeView_drawingShape
(JNIEnv *env, jclass obj) { …Run Code Online (Sandbox Code Playgroud)