我有两个项目:
自定义视图是在 AAR 库中实现的,它从资源中扩展了一个额外的布局:
public class MyCustomView extends ViewGroup {
...
public MyCustomView(Context context) {
super(context);
ctor(context, null, 0);
}
public MyCustomView(Context context, AttributeSet attrs) {
super(context, attrs);
ctor(context, attrs, 0);
}
public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
ctor(context, attrs, defStyle);
}
private void ctor(Context context, AttributeSet attrs, int defStyle) {
View rootView = inflate(context, R.layout.mycustomview, this);
...
}
Run Code Online (Sandbox Code Playgroud)
该视图在单元测试模块上完美运行,无论是在手机上还是在 AS 的预览上。
在第二个应用程序项目上,从 Android Studio 的预览版启动时 …