Android仿iPhone滚轮控件实现及源码分析


敬告:由于本文代码较多,所以文章分为了很多页,如果不便,敬请谅解,可以先下载文章下方的代码,打开参考本文查看,效果更好!

首先,先看下Android仿iPhone滚轮控件效果图:

这三张图分别是使用滚动控件实现城市,随机数和时间三个简单的例子,当然,界面有点简陋,下面我们就以时间这个为例,开始解析一下。

首先,先看下布局文件:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:layout_height="wrap_content"  
  5.     android:layout_width="fill_parent"  
  6.     android:layout_marginTop="12dp"  
  7.     android:orientation="vertical"  
  8.     android:background="@drawable/layout_bg">  
  9.       
  10.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  11.         android:layout_height="wrap_content"  
  12.         android:layout_width="fill_parent"  
  13.         android:layout_gravity="center_horizontal"  
  14.         android:paddingLeft="12dp"  
  15.         android:paddingRight="12dp"  
  16.         android:paddingTop="10dp">  
  17.         
  18.         <kankan.wheel.widget.WheelView android:id="@+id/hour"  
  19.             android:layout_height="wrap_content"  
  20.             android:layout_width="fill_parent"  
  21.             android:layout_weight="1"/>  
  22.         <kankan.wheel.widget.WheelView android:id="@+id/mins"  
  23.             android:layout_height="wrap_content"  
  24.             android:layout_width="fill_parent"  
  25.             android:layout_weight="1"/>  
  26.     </LinearLayout>  
  27.       
  28.     <TimePicker android:id="@+id/time"  
  29.         android:layout_marginTop="12dp"  
  30.         android:layout_height="wrap_content"  
  31.         android:layout_width="fill_parent"  
  32.         android:layout_weight="1"/>  
  33.           
  34. </LinearLayout>  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 下一页

相关内容