我有一个用户在表单中回答问题的项目。 我需要实现一个水平进度条(不是对话框),用点代替普通条。
当用户回答一个问题时,该特定问题的圆点会改变颜色。 这个有可能?我将 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/