你好,游客 登录 注册 搜索
背景:
阅读新闻

Android-仿iPhone滚轮控件效果

[日期:2011-09-14] 来源:Linux社区  作者:shaojie519 [字体:大 中 小]

Android-仿iPhone滚轮控件效果源码下载地址在Linux公社的1号FTP服务器里,下载地址:

FTP地址:ftp://www.linuxidc.com

用户名:www.linuxidc.com

密码:www.muu.cc

在 2011年LinuxIDC.com\9月\Android-仿iPhone滚轮控件效果源码

下载方法见这里 http://www.linuxidc.net/thread-1187-1-1.html

主布局文件

  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:orientation="vertical"  
  6.     android:background="@drawable/layout_bg"  
  7.     android:layout_width="fill_parent">  
  8.       
  9.     <TextView  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content"  
  12.         android:layout_marginTop="24dp"  
  13.         android:layout_gravity="center_horizontal"  
  14.         android:textSize="20sp"  
  15.         android:textStyle="bold"  
  16.         android:text="Please enter PIN"/>  
  17.           
  18.     <LinearLayout  
  19.         android:layout_marginTop="24dp"  
  20.         android:layout_gravity="center_horizontal"  
  21.         android:layout_width="wrap_content"  
  22.         android:layout_height="wrap_content">  
  23.           
  24.         <kankan.wheel.widget.WheelView android:id="@+id/passw_1"  
  25.             android:layout_height="wrap_content"  
  26.             android:layout_width="wrap_content"/>  
  27.         <kankan.wheel.widget.WheelView android:id="@+id/passw_2"  
  28.             android:layout_height="wrap_content"  
  29.             android:layout_width="wrap_content"/>  
  30.         <kankan.wheel.widget.WheelView android:id="@+id/passw_3"  
  31.             android:layout_height="wrap_content"  
  32.             android:layout_width="wrap_content"/>  
  33.         <kankan.wheel.widget.WheelView android:id="@+id/passw_4"  
  34.             android:layout_height="wrap_content"  
  35.             android:layout_width="wrap_content"/>  
  36.         <kankan.wheel.widget.WheelView android:id="@+id/passw_5"  
  37.         android:layout_height="wrap_content"  
  38.         android:layout_width="wrap_content"/>  
  39.         <kankan.wheel.widget.WheelView android:id="@+id/passw_6"  
  40.         android:layout_height="wrap_content"  
  41.         android:layout_width="wrap_content"/>  
  42.     </LinearLayout>  
  43.       
  44.    <TextView android:id="@+id/pwd_status"  
  45.         android:layout_width="wrap_content"  
  46.         android:layout_height="wrap_content"  
  47.         android:layout_marginTop="24dp"  
  48.         android:layout_gravity="center_horizontal"  
  49.         android:textSize="18sp"  
  50.         android:textColor="#FFF"  
  51.         android:text="Wrong PIN"/>  
  52.       
  53.     <Button android:id="@+id/btn_mix"  
  54.         android:layout_width="wrap_content"  
  55.         android:layout_height="wrap_content"  
  56.         android:layout_gravity="center_horizontal"  
  57.         android:layout_marginTop="12dp"  
  58.         android:textSize="18sp"  
  59.         android:text="   Mix  "/>  
  60.   
  61. </LinearLayout>  
适配器adapter
  1. /* 
  2.  *  Copyright 2010 Yuri Kanivets 
  3.  * 
  4.  *  Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  *  you may not use this file except in compliance with the License. 
  6.  *  You may obtain a copy of the License at 
  7.  * 
  8.  *  http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  *  Unless required by applicable law or agreed to in writing, software 
  11.  *  distributed under the License is distributed on an "AS IS" BASIS, 
  12.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  *  See the License for the specific language governing permissions and 
  14.  *  limitations under the License. 
  15.  */  
  16.   
  17. package kankan.wheel.widget;  
  18.   
  19. public interface WheelAdapter {  
  20.     /** 
  21.      * Gets items count 
  22.      * @return the count of wheel items 
  23.      */  
  24.     public int getItemsCount();  
  25.       
  26.     /** 
  27.      * Gets a wheel item by index. 
  28.      *  
  29.      * @param index the item index 
  30.      * @return the wheel item text or null 
  31.      */  
  32.     public String getItem(int index);  
  33.       
  34.     /** 
  35.      * Gets maximum item length. It is used to determine the wheel width.  
  36.      * If -1 is returned there will be used the default wheel width. 
  37.      *  
  38.      * @return the maximum item length or -1 
  39.      */  
  40.     public int getMaximumLength();  
  41. }  

 
  1. /* 
  2.  *  Copyright 2010 Yuri Kanivets 
  3.  * 
  4.  *  Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  *  you may not use this file except in compliance with the License. 
  6.  *  You may obtain a copy of the License at 
  7.  * 
  8.  *  http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  *  Unless required by applicable law or agreed to in writing, software 
  11.  *  distributed under the License is distributed on an "AS IS" BASIS, 
  12.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  *  See the License for the specific language governing permissions and 
  14.  *  limitations under the License. 
  15.  */  
  16.   
  17. package kankan.wheel.widget;  
  18.   
  19.   
  20. /** 
  21.  * Numeric Wheel adapter. 
  22.  */  
  23. public class NumericWheelAdapter implements WheelAdapter {  
  24.       
  25.     /** The default min value */  
  26.     public static final int DEFAULT_MAX_VALUE = 9;  
  27.   
  28.     /** The default max value */  
  29.     private static final int DEFAULT_MIN_VALUE = 0;  
  30.       
  31.     // Values   
  32.     private int minValue;  
  33.     private int maxValue;  
  34.       
  35.     // format   
  36.     private String format;  
  37.       
  38.     /** 
  39.      * Default constructor 
  40.      */  
  41.     public NumericWheelAdapter() {  
  42.         this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE);  
  43.     }  
  44.   
  45.     /** 
  46.      * Constructor 
  47.      * @param minValue the wheel min value 
  48.      * @param maxValue the wheel max value 
  49.      */  
  50.     public NumericWheelAdapter(int minValue, int maxValue) {  
  51.         this(minValue, maxValue, null);  
  52.     }  
  53.   
  54.     /** 
  55.      * Constructor 
  56.      * @param minValue the wheel min value 
  57.      * @param maxValue the wheel max value 
  58.      * @param format the format string 
  59.      */  
  60.     public NumericWheelAdapter(int minValue, int maxValue, String format) {  
  61.         this.minValue = minValue;  
  62.         this.maxValue = maxValue;  
  63.         this.format = format;  
  64.     }  
  65.   
  66.     @Override  
  67.     public String getItem(int index) {  
  68.         if (index >= 0 && index < getItemsCount()) {  
  69.             int value = minValue + index;  
  70.             return format != null ? String.format(format, value) : Integer.toString(value);  
  71.         }  
  72.         return null;  
  73.     }  
  74.   
  75.     @Override  
  76.     public int getItemsCount() {  
  77.         return maxValue - minValue + 1;  
  78.     }  
  79.       
  80.     @Override  
  81.     public int getMaximumLength() {  
  82.         int max = Math.max(Math.abs(maxValue), Math.abs(minValue));  
  83.         int maxLen = Integer.toString(max).length();  
  84.         if (minValue < 0) {  
  85.             maxLen++;  
  86.         }  
  87.         return maxLen;  
  88.     }  
  89. }  

监听器Listener文件:

  1. /* 
  2.  *  Copyright 2010 Yuri Kanivets 
  3.  * 
  4.  *  Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  *  you may not use this file except in compliance with the License. 
  6.  *  You may obtain a copy of the License at 
  7.  * 
  8.  *  http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  *  Unless required by applicable law or agreed to in writing, software 
  11.  *  distributed under the License is distributed on an "AS IS" BASIS, 
  12.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  *  See the License for the specific language governing permissions and 
  14.  *  limitations under the License. 
  15.  */  
  16.   
  17. package kankan.wheel.widget;  
  18.   
  19. /** 
  20.  * Wheel scrolled listener interface. 
  21.  */  
  22. public interface OnWheelScrollListener {  
  23.     /** 
  24.      * Callback method to be invoked when scrolling started. 
  25.      * @param wheel the wheel view whose state has changed. 
  26.      */  
  27.     void onScrollingStarted(WheelView wheel);  
  28.       
  29.     /** 
  30.      * Callback method to be invoked when scrolling ended. 
  31.      * @param wheel the wheel view whose state has changed. 
  32.      */  
  33.     void onScrollingFinished(WheelView wheel);  
  34. }  

 
  1. /* 
  2.  *  Copyright 2010 Yuri Kanivets 
  3.  * 
  4.  *  Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  *  you may not use this file except in compliance with the License. 
  6.  *  You may obtain a copy of the License at 
  7.  * 
  8.  *  http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  *  Unless required by applicable law or agreed to in writing, software 
  11.  *  distributed under the License is distributed on an "AS IS" BASIS, 
  12.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  *  See the License for the specific language governing permissions and 
  14.  *  limitations under the License. 
  15.  */  
  16.   
  17. package kankan.wheel.widget;  
  18.   
  19. /** 
  20.  * Wheel changed listener interface. 
  21.  * <p>The currentItemChanged() method is called whenever current wheel positions is changed: 
  22.  * <li> New Wheel position is set 
  23.  * <li> Wheel view is scrolled 
  24.  */  
  25. public interface OnWheelChangedListener {  
  26.     /** 
  27.      * Callback method to be invoked when current item changed 
  28.      * @param wheel the wheel view whose state has changed 
  29.      * @param oldValue the old value of current item 
  30.      * @param newValue the new value of current item 
  31.      */  
  32.     void onChanged(WheelView wheel, int oldValue, int newValue);  
  33. }  
linux
相关资讯       Android开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款