无效重绘api 25上的视图

时间:2017-01-03 10:36:00

标签: android

我有一个扩展LinearLayout的自定义视图。 视图看起来像进度条,每个点击都会移动一个小图标。 更新方法是:

public void setPointerOffset(int mPointerOffset) {
    this.mPointerOffset = mPointerOffset;
    updateSlider();
    invalidate();
    requestLayout();
}
private void updateSlider() {
    PercentFrameLayout.LayoutParams params = (PercentFrameLayout.LayoutParams) mPointer.getLayoutParams();
    PercentLayoutHelper.PercentLayoutInfo info = params.getPercentLayoutInfo();
    if (mPointerOffset < MIN_OFFSET)
        mPointerOffset = MIN_OFFSET;
    if (mPointerOffset > MAX_OFFSET)
        mPointerOffset = MAX_OFFSET;
    float percent = mPointerOffset * 0.01f;
    info.startMarginPercent = percent;
}

此方法是从onClickListener启动的。 这在17岁的低api中运行良好,但是至于(25)它根本不起作用。

1 个答案:

答案 0 :(得分:0)

将布局参数设置为&#34; mPointer&#34; semms来解决它。

private void updateSlider() {
    PercentFrameLayout.LayoutParams params = (PercentFrameLayout.LayoutParams) mPointer.getLayoutParams();
    PercentLayoutHelper.PercentLayoutInfo info = params.getPercentLayoutInfo();
    if (mPointerOffset < MIN_OFFSET)
        mPointerOffset = MIN_OFFSET;
    if (mPointerOffset > MAX_OFFSET)
        mPointerOffset = MAX_OFFSET;
    float percent = mPointerOffset * 0.01f;
    info.startMarginPercent = percent;
    mPointer.setLayoutParams(params);
}