Android自定义ProgressBar,带有左右轨迹图像

Android自定义ProgressBar,带有左右轨迹图像,android,android-progressbar,Android,Android Progressbar,我正在将一个iOS应用程序移植到Android上,iOS应用程序中的一个功能是一个自定义的UISlider,它使用左右轨迹图像(如下图所示),但到目前为止,我似乎无法在Android端复制同样的行为 从图像中,您可以看到右轨迹图像使用白色图像,然后左轨迹图像将是红色或绿色图像(取决于此人离目标的距离)。下面是ProgressBar的XML(顺便说一句,我似乎无法确定ProgressBar或SeekerBar是否是这里的最佳选择,因为这里没有交互,并且显示后该条不会改变,因为它更像一个条形图类型

我正在将一个iOS应用程序移植到Android上,iOS应用程序中的一个功能是一个自定义的UISlider,它使用左右轨迹图像(如下图所示),但到目前为止,我似乎无法在Android端复制同样的行为

从图像中,您可以看到右轨迹图像使用白色图像,然后左轨迹图像将是红色或绿色图像(取决于此人离目标的距离)。下面是ProgressBar的XML(顺便说一句,我似乎无法确定ProgressBar或SeekerBar是否是这里的最佳选择,因为这里没有交互,并且显示后该条不会改变,因为它更像一个条形图类型的图像)

这是我的进度条的XML数据

<TableRow
            android:id="@+id/MTDRow"
            android:layout_width="match_parent"
              android:layout_height="55dip">
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        <ProgressBar
                android:id="@+id/MTDBackgroundBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxHeight="44dip"
            android:minHeight="44dip"
            android:paddingLeft="10dip"
            style="?android:attr/progressBarStyleHorizontal" />

        <ProgressBar
            android:id="@+id/MTDMainBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dip"
            style="?android:attr/progressBarStyleHorizontal"
            android:maxHeight="44dip"
            android:minHeight="44dip"/>

        </RelativeLayout>
              </TableRow>

我很确定你不能用内置的UI元素来实现这一点,你必须创建自己的自定义UI元素,可能是扩展ProgressBar。

我很确定你不能用内置的UI元素来实现这一点,你必须创建自己的自定义UI元素,可能是扩展ProgressBar

//this is the code in the Fragment Class
@Override
public void onActivityCreated (Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);


    Drawable greentrack = getResources().getDrawable(R.drawable.green_progress_clip);
    greentrack.setLevel(35);

    Drawable whitetrack = getResources().getDrawable(R.drawable.white_progress_clip);
    whitetrack.setLevel(100);

    MTDProgressbar = (ProgressBar)getActivity().findViewById(R.id.MTDMainBar);
    MTDProgressbar.setProgressDrawable(greentrack);
    MTDProgressbar.setProgress(35);
    MTDProgressbar.setMax(100);

    MTDBackgroundbar = (ProgressBar)getActivity().findViewById(R.id.MTDBackgroundBar);
    MTDBackgroundbar.setProgressDrawable(whitetrack);
    MTDBackgroundbar.setProgress(100);
    MTDBackgroundbar.setMax(100);
}
<TableRow
            android:id="@+id/MTDRow"
            android:layout_width="match_parent"
              android:layout_height="55dip">
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        <ProgressBar
                android:id="@+id/MTDBackgroundBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxHeight="44dip"
            android:minHeight="44dip"
            android:paddingLeft="10dip"
            style="?android:attr/progressBarStyleHorizontal" />

        <ProgressBar
            android:id="@+id/MTDMainBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dip"
            style="?android:attr/progressBarStyleHorizontal"
            android:maxHeight="44dip"
            android:minHeight="44dip"/>

        </RelativeLayout>
              </TableRow>