我已经构建了一个非常简单的原生Android UI组件,我想在单击来自我的本机项目的按钮时更新其子视图的大小.更确切地说,当单击此按钮时,我向我发送命令SimpleViewManager,然后调用resizeLayout()我的自定义视图.
我可以验证是否resizeLayout()已正确调用,但在旋转手机之前不会调整布局大小.显然,更改设备的方向会触发draw()我的自定义视图,但invalidate()我明确调用的也是如此.
其他布局更改,如更改背景颜色而不是调整大小工作正常.
我的自定义组件如下所示:
public class CustomComponent extends RelativeLayout {
public CustomComponent(Context context) {
super(context);
init();
}
public CustomComponent(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomComponent(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
inflate(getContext(), R.layout.simple_layout, this);
}
public void resizeLayout(){
LinearLayout childLayout = (LinearLayout) findViewById(R.id.child_layout);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) childLayout.getLayoutParams();
layoutParams.height = 50;
layoutParams.width= 50;
childLayout.setLayoutParams(layoutParams); …Run Code Online (Sandbox Code Playgroud)