【发布时间】:2021-08-12 20:17:37
【问题描述】:
我可以用原生android代码创建一个LinearLayout(例如)并显示在CN1界面上吗?
我有一个实现原生 android 代码的方法来创建这个视图。例如,如果该方法返回一个 EditText 或 Button,则一切正常。但如果它返回一个 LinearLayout,什么都不会发生,我也没有错误消息。
调用本机代码的方法的签名:
public interface NativeCall extends NativeInterface {
public PeerComponent getMainView();
}
运行良好的原生实现代码:
public class NativeCallImpl {
public android.view.View getMainView() {
Button b0 = new Button(((Context) MyApplication.getContext()));
return b0;
}
public boolean isSupported() {
return true;
}
}
本地代码实现不起作用:
public class NativeCallImpl {
public android.view.View getMainView() {
Button b0 = new Button(((Context) MyApplication.getContext()));
Button b1 = new Button(((Context) MyApplication.getContext()));
b0.setText("b0");
b1.setText("b1");
LinearLayout linearLayout = new LinearLayout(((Context) MyApplication.getContext()));
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(b0);
linearLayout.addView(b1);
return linearLayout;
}
public boolean isSupported() {
return true;
}
}
【问题讨论】:
标签: android android-layout codenameone