小编Non*_*upt的帖子

带有自定义视图的 Android Studio 从 AAR 膨胀布局

背景

我有两个项目:

  • 图书馆
    • AAR(安卓库)
    • 单元测试模块
  • 应用程序
    • 主要活动
    • 进口 AAR

自定义视图是在 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 的预览版启动时 …

android static-libraries

5
推荐指数
0
解决办法
540
查看次数

标签 统计

android ×1

static-libraries ×1