Android - 带点的水平进度条

标签 android progress-bar android-progressbar

我有一个用户在表单中回答问题的项目。 我需要实现一个水平进度条(不是对话框),用点代替普通条。

当用户回答一个问题时,该特定问题的圆点会改变颜色。 这个有可能?我将 API 16(目标)和 API 7(最低)与 Sherlock ActionBar 一起使用

最佳答案

如果您没有大量的问题,那么只使用多个 ImageView 来表示点可能就足够了。 XML 示例:

 <RelativeLayout
        android:id="@+id/dotsL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/dot1"
            android:layout_width="5dp"
            android:layout_height="5dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/circle_white" >
        </ImageView>

        <ImageView
            android:id="@+id/dot2"
            android:layout_width="5dp"
            android:layout_height="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@+id/dot1"
            android:background="@drawable/circle_white" >
        </ImageView>

        <ImageView
            android:id="@+id/dot3"
            android:layout_width="5dp"
            android:layout_height="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@+id/dot2"
            android:background="@drawable/circle_white" >
        </ImageView>

        <ImageView
            android:id="@+id/dot4"
            android:layout_width="5dp"
            android:layout_height="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@+id/dot3"
            android:background="@drawable/circle_white" >
        </ImageView>

        <ImageView
            android:id="@+id/dot5"
            android:layout_width="5dp"
            android:layout_height="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@+id/dot4"
            android:background="@drawable/circle_white" >
        </ImageView>
    </RelativeLayout>

在Java中:

    mDots = new ImageView[5];
    mDots[0] = (ImageView) rootView.findViewById(R.id.dot1);
    mDots[1] = (ImageView) rootView.findViewById(R.id.dot2);
    mDots[2] = (ImageView) rootView.findViewById(R.id.dot3);
    mDots[3] = (ImageView) rootView.findViewById(R.id.dot4);
    mDots[4] = (ImageView) rootView.findViewById(R.id.dot5);

当用户回答问题时,只需:

mDots[questionNumber].setBackgroundDrawable(getResources().getDrawable(R.drawable.circle_green));

注意:此方法要求您具有相应的可绘制对象。

关于Android - 带点的水平进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13288754/

相关文章:

php - 将 SQLite/Android 数据库表同步到远程 MySQL 数据库表(通过 PHP)

android - 如何将textView放置在回收器 View 之上?

java - Vert.X Web 客户端进度状态

android - 如何以编程方式在 AsyncTask.onPreExecute 中添加 ProgressBar?

android - 如何在加载数据时实现progressBar?

android - 如何从 Android TV 设备中排除您的应用

java - 在我的应用程序中,我可以进入图库,但在选择图像后,它不会覆盖 "OnActivityResult"方法

java - 小程序加载时的进度条

Android ProgressBar 倒计时

android - 与 Android 5.0 SDK (API 21) 一起使用时,setSupportProgressBarIndeterminateVisibility 引发 java.lang.NullPointerException