歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android仿iPhone滾輪控件實現及源碼分析

Android仿iPhone滾輪控件實現及源碼分析

日期:2017/3/1 10:19:11   编辑:Linux編程

敬告:由於本文代碼較多,所以文章分為了很多頁,如果不便,敬請諒解,可以先下載文章下方的代碼,打開參考本文查看,效果更好!

首先,先看下Android仿iPhone滾輪控件效果圖:

這三張圖分別是使用滾動控件實現城市,隨機數和時間三個簡單的例子,當然,界面有點簡陋,下面我們就以時間這個為例,開始解析一下。

首先,先看下布局文件:

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