gpt4 book ai didi

android - 无法使用 setLayoutParams 更改 View 的宽度/高度

转载 作者:行者123 更新时间:2023-11-29 14:51:25 27 4
gpt4 key购买 nike

我正在尝试在 RelativeLayout(我扩展)中创建正方形子项。在 Activity 开始时它工作正常,但是当加载广告时,我的相对布局变小但我的代码不会影响 child 。来自扩展 RelativeLayout 的代码:

protected void onSizeChanged(int w, int h, int oldw, int oldh) {
int minSize = Math.min(w, h);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageViewContainer.getLayoutParams();
layoutParams.width = minSize;
layoutParams.height = minSize;
imageViewContainer.setLayoutParams(layoutParams);
invalidate();
}

最佳答案

尝试更改覆盖 onMeasure 方法的值,同样在您的代码中我会自己调用 measure() 或 requestLayout()

关于android - 无法使用 setLayoutParams 更改 View 的宽度/高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16820021/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com