相关疑难解决方法(0)

React Native:调整自定义UI组件的大小

我已经构建了一个非常简单的原生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)

android react-native

7
推荐指数
1
解决办法
2382
查看次数

反应原生 UI 组件

当 react native 多次需要这个原生 ui 组件时,从第二个开始,前一个变成黑色。

有任何想法吗?

@Override
public String getName()
{
    return "JWPlayer";
}


@Override
public JWPlayerView createViewInstance(ThemedReactContext context)
{
    PlayerConfig playerConfig = new PlayerConfig.Builder().build();

    playerView = new JWPlayerView(context.getCurrentActivity(), playerConfig);
    playerView.setFullscreen(false, false);
    playerView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    playerView.addOnFullscreenListener(this);
    playerView.addOnPauseListener(this);
    playerView.addOnPlayListener(this);
    playerView.addOnSetupErrorListener(this);
    playerView.addOnErrorListener(this);



    return playerView;
}
Run Code Online (Sandbox Code Playgroud)

react-native react-native-component

2
推荐指数
1
解决办法
1262
查看次数