问题
最近在开发aar文件,在本地module之中直接依赖。显示正常。
但是打包成aar文件,给到其他小伙伴进行依赖的时候,出现了布局混乱问题。
ConstraintLayout.LayoutParams clParams =(ConstraintLayout.LayoutParams)zinyanView.getLayoutParams();
if (clParams.matchConstraintPercentWidth == 0.5f) {
clParams.matchConstraintPercentHeight = 1.0f;
clParams.matchConstraintPercentWidth = 1.0f;
zinyanView.bringToFront(); //将当前View 调整到Layout的最上层显示。
} else {
clParams.matchConstraintPercentHeight = 0.5f;
clParams.matchConstraintPercentWidth = 0.5f;
}
zinyanView.setLayoutParams(clParams);
我需要自定义View 获取点击的时候放大尺寸,然后再点击缩小尺寸。
使用的ConstraintLayout 布局包裹。
结果我本地依赖正常,其他人依赖就会失败。
解决
查询一通后发现ConstraintLayout 有了一个新的工具类。 ConstraintSet 。
然后说建议使用ConstraintSet 来实现。 具体的ConstraintSet 有空了出一个相关配置说明吧。
结果,任然没有效果。我本地可以正常布局的放大切换。但是远程依赖还是会出现错误。
实在没办法了。重构采用自定义ViewGroup方式来实现。
小插曲:ViewGroup的控件刷新 requestLayout(); 这个方法才会触发onMeasure 和onLayout() 方法
结果任然不行。布局出现了其他的尺寸适配问题。
最终:发现默认依赖的库的问题
我的aar里面依赖的下面的库的版本,要比集成我的库的其他小伙伴上的版本要高。
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
就因为这个问题,造成了我的aar 配置的Layout布局信息在他的项目中使用时出现了问题。
我通过调整这个版本,解决了我的问题。
记录一下。
评论区