离散搜索栏的Andr​​oid应用程序?

问题描述:

我想创建一个搜索栏的Andr​​oid应用程序,允许用户选择-5和5之间的值(它映射到强烈不同意和非常同意)。如何使离散值的搜索栏?或者有更好的UI控件,我可以用呢?

i would like to create a seekbar for an Android app that allows the user to select a value between -5 and 5 (which maps to "strongly disagree" and "strongly agree"). how do i make a seekbar with discrete values? or is there a better UI widget i could use for this?

感谢。

搜索栏的离散值的伟大工程。我们使用搜索栏进行离散数据,如下图所示。要显示选择哪个项目,我们只是改变所选文本视图的字体,因此较大。您也可以通过更改背景颜色或东西突出。它的工作原理pretty的好。您将要调用SETMAX(11)上的搜索栏,然后在你的code,你需要(-5〜5)适当的范围内(0〜11)之间进行转换。

The Seekbar works great for discrete values. We use a Seekbar for discrete data as shown below. To show which item is selected, we just change the font of the selected text view so it is bigger. You could also highlight by changing the background color or something. It works pretty well. You will want to call setMax(11) on the seek bar, and then in your code you need to translate between the range (0 through 11) and (-5 through 5) appropriately.

 <LinearLayout 
           android:orientation="vertical"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:gravity="center_horizontal">
     <LinearLayout 
           android:orientation="horizontal"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:gravity="center_horizontal">
    <TextView android:text="-5"
            android:id="@+id/answerNegative5"
            android:textSize="25sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    <TextView android:text="-4"
            android:id="@+id/answerNegative4"
            android:textSize="25sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    <TextView android:text="-3"
            android:id="@+id/answerNegative3"
            android:textSize="25sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    .....
  </LinearLayout>

  <SeekBar android:id="@+id/intensitySlider"
                    android:layout_weight="0"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />
</LinearLayout>