【问题标题】:time picker with scroll for android?安卓滚动时间选择器?
【发布时间】:2013-02-22 11:01:27
【问题描述】:

我希望在我的主视图中有两个用于选择时间的滚轮,一个包含 01-24 的数字,另一个包含 00-60,跳跃为 5 (0,5,10..55) 有没有为这样的事情做好准备? 类似于http://code.google.com/p/mobiscroll/,只是内置了android。 时间选择器很烦人..我需要按 +- 直到我选择我想要的。我更喜欢更直观的东西。 对于这样的事情,我有哪些选择?

【问题讨论】:

  • 我做过类似的事情。但该列表不是循环的。你需要代码吗?
  • 我不在乎它是否是圆形的,我只需要一些可滚动的东西。没有什么“专家”。同时我会尝试其他建议
  • 这对我有用。它在列表视图上创建快照效果。如果您需要 xml,请告诉我。
  • 你可以添加你的自定义背景,让事情看起来更好。

标签: android android-layout timepicker


【解决方案1】:

没有内置任何东西,但你可以试试这个: http://code.google.com/p/android-wheel/

【讨论】:

  • 我尝试将文件夹导入为android项目,错误为:[2013-02-22 15:27:42 - Main] Unable to resolve target 'android-3' [2013-02-22 15:44:29 - wheel] Unable to resolve target 'android-7'
【解决方案2】:

在这里,您将找到一个包含源代码的完整项目。 TestWheel.zip

  1. 从链接下载TestWheel.zip
  2. 在你的 Eclipse 中导入它
  3. 将此项目转换为库项目(右键单击 testWheel 项目 ==> 属性 ==> android ==> 选中 is library 复选框)。
  4. 将此库项目添加到您的项目中。
  5. 将以下代码复制并粘贴到您的 XML 文件中。

【讨论】:

  • 您现在遇到了什么错误?甚至昨天我已经实施了这一点。它对我有好处。
  • [2013-02-22 15:27:42 - Main] Unable to resolve target 'android-3' [2013-02-22 15:44:29 - wheel] Unable to resolve target 'android-7' 等错误
  • 在你的清单文件中设置
  • 并清理你的项目
【解决方案3】:

这是您的 hour_listView。只需为其设置一个字符串适配器。假设您可以使用 ArrayAdapter 填充 listView。

        hr_list.setOnScrollListener(new OnScrollListener() {

            int currentcount,topitem,firstitem,lastitem;
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                if (scrollState == SCROLL_STATE_IDLE && currentcount == 4) {
                    while (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
                    }

                    LinearLayout item = (LinearLayout) view.getChildAt(0);
                    int height = item.getHeight();
                    int top = Math.abs(item.getTop()); // top is a negative value

                    if (top <= height/2){
                        view.smoothScrollToPositionFromTop(topitem, 0, 3000);
                        Log.d("Switch", "up");
                    }
                    if(top> height/2){
                        view.smoothScrollToPositionFromTop(topitem+1, 0,3000);
                        Log.d("Switch", "down");
                    }
                }
            }

然后在 button.clickListener 上设置,你会得到可见 listView 的中心行号。

int list_hr = hr_list.getFirstVisiblePosition() - hr_list.getHeaderViewsCount();

几个关键点。 * 为 listView 1dp 设置分隔线高度。 *使用线性布局在listView中插入 行高应该是列表视图总高度的 1/3(以 dp 为单位)。

列表视图和按钮的 XML

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Snap List"
    android:textSize="25sp" />

<ListView
    android:id="@+id/listView1"
    android:layout_width="100dp"
    android:layout_height="120dp"
    android:fadingEdgeLength="33dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="73dp"
    android:background="@drawable/lisbg"
    android:scrollbars="none" >
</ListView>

<StackView
    android:id="@+id/stackView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/listView1"
    android:layout_marginLeft="103dp"
    android:layout_marginTop="57dp"
    android:layout_toRightOf="@+id/textView1" >
</StackView>

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView1"
    android:layout_marginRight="58dp"
    android:text="OK" />

<Button
    android:id="@+id/button2"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button1"
    android:layout_below="@+id/button1"
    android:text="Scroll 5" />

行的 XML。

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:textSize="25sp"
    android:gravity="center_vertical|center_horizontal"
    android:layout_gravity="center_vertical|center_horizontal"
    android:text="TextView" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-11
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    • 2010-10-27
    • 2013-08-04
    相关资源
    最近更新 更多