2013-02-22 57 views
0

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

+0

我已经做了类似的事情。但名单不是循环的。你需要代码吗? – 2013-02-22 11:52:23

+0

我不在乎它是否是循环的,我只需要一些可滚动的东西。没有什么是“专家”。同时我会尝试其他建议 – buddy123 2013-02-22 13:05:55

+0

这适用于我的。它在列表视图上创建快照效果。如果你需要这个XML,请告诉我。 – 2013-02-22 13:31:03

回答

0

没有什么建立,但你可以试试这个: http://code.google.com/p/android-wheel/

+0

我试图导入文件夹为android项目,错误是:[2013-02-22 15:27:42 - Main]无法解析目标'android-3' [2013-02-22 15:44: 29 - 轮]无法解决目标'android-7' ' – buddy123 2013-02-22 13:45:18

0

你会发现这里的源代码一个完整的项目。 TestWheel.zip

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

enter image description here

+0

它也会导致错误。因为我发布在其他建议 – buddy123 2013-02-22 13:50:08

+0

你现在得到什么错误?我甚至在昨天实施了这个。它对我有好处。 – 2013-02-22 18:20:18

+0

错误,如'[2013-02-22 15:27:42 - 主]无法解决目标'android-3'[2013-02-22 15:44:29 - wheel]无法解析目标'android-7 '' – buddy123 2013-02-22 19:16:17

0

这是你的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的分隔高度。 *使用线性布局在列表视图中排列 行高应该是列表视图高度(在dp中)的1/3。

XML的ListView和按钮

<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" />