不生效代码:

public void initSpeedView(boolean hasPark) {
    lightNavSpeedView = new LightNavSpeedView(getNaviActivity());
    RelativeLayout.LayoutParams lightNavSpeedViewLayoutParams = getWrapLayoutParams();
    lightNavSpeedViewLayoutParams
            .addRule(RelativeLayout.END_OF, lightNavGuideView.getView().getId());
    int leftMargin = hasPark ?
    getDimen(R.dimen.light_nav_speed_view_margin_left)
            - (getDimen(R.dimen.navi_end_card_panel_width)
            - getDimen(R.dimen.light_navi_route_guide_panel_width))
                    :getDimen(R.dimen.light_nav_speed_view_margin_left);
    lightNavSpeedViewLayoutParams.setMargins(
            leftMargin,
            getDimen(R.dimen.light_nav_speed_view_margin_top),
            getDimen(R.dimen.light_nav_speed_view_margin_right),
            getDimen(R.dimen.light_nav_speed_view_margin_bottom));
    if (mViewGroup.findViewById(R.id.linearLightNavSpeedRootView) != null) {
        mViewGroup.findViewById(R.id.linearLightNavSpeedRootView).setLayoutParams(lightNavSpeedViewLayoutParams);
    } else {
        mViewGroup.addView(lightNavSpeedView.getView(), lightNavSpeedViewLayoutParams);
    }
}

解决方式分为二种:

第一种使用remove然后在add的方式:

if (mViewGroup.findViewById(R.id.linearLightNavSpeedRootView) != null) {

    mViewGroup.removeView(mViewGroup.findViewById(R.id.linearLightNavSpeedRootView));

}

mViewGroup.addView(lightNavSpeedView.getView(), lightNavSpeedViewLayoutParams);

public void initSpeedView(boolean hasPark) {
        lightNavSpeedView = new LightNavSpeedView(getNaviActivity());
        RelativeLayout.LayoutParams lightNavSpeedViewLayoutParams = getWrapLayoutParams();
        if (ChannelUtil.isC1YCChannel()) {
            lightNavSpeedViewLayoutParams.width = getDimen(R.dimen.navi_rg_interval_camera_bg_size);
            lightNavSpeedViewLayoutParams.height = getDimen(R.dimen.navi_rg_interval_camera_bg_size);
        }
        lightNavSpeedViewLayoutParams
                .addRule(RelativeLayout.END_OF, lightNavGuideView.getView().getId());
        int leftMargin = hasPark?
        getDimen(R.dimen.light_nav_speed_view_margin_left)
                - (getDimen(R.dimen.navi_end_card_panel_width)
                - getDimen(R.dimen.light_navi_route_guide_panel_width))
                        :getDimen(R.dimen.light_nav_speed_view_margin_left);
        lightNavSpeedViewLayoutParams.setMargins(
                leftMargin,
                getDimen(R.dimen.light_nav_speed_view_margin_top),
                getDimen(R.dimen.light_nav_speed_view_margin_right),
                getDimen(R.dimen.light_nav_speed_view_margin_bottom));
        if (mViewGroup.findViewById(R.id.linearLightNavSpeedRootView) != null) {
            mViewGroup.removeView(mViewGroup.findViewById(R.id.linearLightNavSpeedRootView));
        }
        mViewGroup.addView(lightNavSpeedView.getView(), lightNavSpeedViewLayoutParams);
    }

第二种更换xml布局把右对齐换位做对齐:

核心更改:RelativeLayout.END_OF 改为:RelativeLayout.ALIGN_LEFT,

lightNavSpeedViewLayoutParams
        .addRule(RelativeLayout.ALIGN_LEFT, lightNavGuideView.getView().getId());
 private void initSpeedView() {
        lightNavSpeedView = new LightNavSpeedView(getNaviActivity());
        RelativeLayout.LayoutParams lightNavSpeedViewLayoutParams = getWrapLayoutParams();
        if (ChannelUtil.isC1YCChannel()) {
            lightNavSpeedViewLayoutParams.width = getDimen(R.dimen.navi_rg_interval_camera_bg_size);
            lightNavSpeedViewLayoutParams.height = getDimen(R.dimen.navi_rg_interval_camera_bg_size);
        }
        lightNavSpeedViewLayoutParams
                .addRule(RelativeLayout.ALIGN_LEFT, lightNavGuideView.getView().getId());
        lightNavSpeedViewLayoutParams.setMargins(
                getDimen(R.dimen.light_nav_speed_view_margin_left)
                        +  getDimen(R.dimen.light_navi_route_guide_panel_width),
                getDimen(R.dimen.light_nav_speed_view_margin_top),
                getDimen(R.dimen.light_nav_speed_view_margin_right),
                getDimen(R.dimen.light_nav_speed_view_margin_bottom));
        mViewGroup.addView(lightNavSpeedView.getView(), lightNavSpeedViewLayoutParams);
    }

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐