0

伙计们,我正在扩展进度条,我正在更改进度条的高度并设置它的填充。除了底部填充外,一切正常。问题是当我尝试遵循代码时,它只显示顶部填充,而没有底部填充。

@Override
protected synchronized void onMeasure(int widthMeasureSpec,
        int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(getMeasuredWidth(), mMaxThumbDrawable.getHeight());
    if(getWidth() > 0)
        mPixels = getWidth() / mRange;
    paddintBottom = (int)(0.8f * getHeight());
    paddintTop = (int)(0.4f * getHeight());
    setPadding(0, paddintTop, 0, paddintBottom);
}

XML如下

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

    <com.example.customseekbarwidget.DoubleSlider
    android:id="@+id/doubleSlider1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:progressDrawable="@drawable/progress_bar_bg" />

</LinearLayout>

问题的有趣部分是,如果我指定像 44 这样的常量值来代替 paddintBottom 像

setPadding(0, paddintTop, 0, 44);

它突然开始工作,但我无法保持值不变。任何人都对此有任何想法。

在此处输入图像描述

4

0 回答 0