Android仿iPhone滚轮控件实现及源码分析
Android仿iPhone滚轮控件实现及源码分析
敬告:由于本文代码较多,所以文章分为了很多页,如果不便,敬请谅解,可以先下载文章下方的代码,打开参考本文查看,效果更好!
首先,先看下Android仿iPhone滚轮控件效果图:
这三张图分别是使用滚动控件实现城市,随机数和时间三个简单的例子,当然,界面有点简陋,下面我们就以时间这个为例,开始解析一下。
首先,先看下布局文件:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:layout_marginTop="12dp"
- android:orientation="vertical"
- android:background="@drawable/layout_bg">
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:layout_gravity="center_horizontal"
- android:paddingLeft="12dp"
- android:paddingRight="12dp"
- android:paddingTop="10dp">
- <kankan.wheel.widget.WheelView android:id="@+id/hour"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:layout_weight="1"/>
- <kankan.wheel.widget.WheelView android:id="@+id/mins"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:layout_weight="1"/>
- </LinearLayout>
- <TimePicker android:id="@+id/time"
- android:layout_marginTop="12dp"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:layout_weight="1"/>
- </LinearLayout>
|
评论暂时关闭