Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-带点的水平进度条_Android_Progress Bar_Android Progressbar - Fatal编程技术网

Android-带点的水平进度条

Android-带点的水平进度条,android,progress-bar,android-progressbar,Android,Progress Bar,Android Progressbar,我有一个项目,用户在表单中回答问题。 我需要实现一个水平进度条(不是对话框),用点代替普通条 当用户回答一个问题时,该特定问题的圆点会改变颜色。 这是可能的吗?我在Sherlock ActionBar中使用API 16(目标)和API 7(最小值)如果您没有太多的问题,那么只使用多个图像视图来表示点就足够了。XML示例: <RelativeLayout android:id="@+id/dotsL" android:layout_width="wrap_c

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

当用户回答一个问题时,该特定问题的圆点会改变颜色。
这是可能的吗?我在Sherlock ActionBar中使用API 16(目标)和API 7(最小值)

如果您没有太多的问题,那么只使用多个图像视图来表示点就足够了。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>
当用户回答问题时,只需:

mDots[questionNumber].setBackgroundDrawable(getResources().getDrawable(R.drawable.circle_green));
注意:此方法要求您具有相应的可绘图项。

XML:

<LinearLayout
    android:id="@+id/image_layout"
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical">

我刚刚改进了slezadav的建议。

Android框架中已经包含了ProgressBar小部件。这适用于所有类型的布局,并且不限于对话框。使用它并指定android:progressDrawable或android:UndeterminatedDrawable属性以及您自己的dots drawable将是最简单的解决方案。有关详细信息,请参阅。

我认为如果我已经知道用户将回答的问题数量,但问题数量不在我的控制范围内,那么这将起作用。用户在网站中创建表单,他可以创建一个包含10个问题或100个问题的表单。我不能在xml中使用固定数量的点,我必须用N个工厂以编程方式对它们进行实例化。在这种情况下,你是对的,你必须以编程方式实例化ImageView,这当然是可能的。也许不是解决这个问题的最干净的方法,但它应该有效。我会测试这个,明天我会发布反馈,tkz!虽然我还没有测试过,但我很确定它是有效的。这可能是个小问题。试试这个
<LinearLayout
    android:id="@+id/image_layout"
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical">
ImageView[] images = new ImageView[totQuestions];
LinearLayout imageLayout = (LinearLayout) findViewById(R.id.image_layout);  
ImageView image;
LinearLayout.LayoutParams layoutParams;
for(int i = 0; i < totQuestions; i++){
    image = new ImageView(this);
    layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f);
    image.setLayoutParams(layoutParams);
    image.setBackgroundDrawable(getResources().getDrawable(R.drawable.circle_green));
    image.setVisibility(View.INVISIBLE);
    images[i] = image;
    imageLayout.addView(image);
}
imageLayout.getChildAt(questionNr).setVisibility(View.VISIBLE); //starting at 0