I found a working solution.. Probably not the best, so comments are appriciated!
in my xml-file
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/info"
/>
<LinearLayout
android:id="@+id/take_test_progress_bar_linear_layout"
android:layout_width="match_parent"
android:layout_height="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_below="@+id/info"
android:orientation="horizontal" >
</LinearLayout>
<TextView
android:id="@+id/question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/take_test_progress_bar_linear_layout"
android:text="@string/stt1"
/>
And in my activity:
oncreate(){
....
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
for(int k=0; k<mTotalQuestionNum; k++)
{
View v = new View(this);
v.setBackgroundColor(Color.GRAY);
params.weight = (float)1.0/( (float) mTotalQuestionNum);
v.setLayoutParams(params);
mProgressLayout.addView(v,k);
}
...
}
Then, when handling answers...
if(correct)
mProgressLayout.getChildAt(mQuestionNum-1).setBackgroundColor(Color.GREEN);
else
mProgressLayout.getChildAt(mQuestionNum-1).setBackgroundColor(Color.RED);