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:orientation="vertical" android:background="@drawable/layout_bg" android:layout_width="fill_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:layout_gravity="center_horizontal" android:textSize="20sp" android:text="Please select the city" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:paddingLeft="12dp" android:paddingRight="12dp" android:paddingTop="4dp" android:layout_marginTop="8dp" android:orientation="horizontal"> <kankan.wheel.widget.WheelView android:id="@+id/country" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" /> <kankan.wheel.widget.WheelView android:id="@+id/city" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="10dp" android:layout_weight="1.5" /> </LinearLayout> <!-- Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="18dp" android:textSize="18sp" android:text=" Next > "/ --> </LinearLayout>
package kankan.wheel.demo;import kankan.wheel.R; import kankan.wheel.widget.ArrayWheelAdapter; import kankan.wheel.widget.OnWheelChangedListener; import kankan.wheel.widget.WheelView;
import android.app.Activity; import android.os.Bundle;
public class CitiesActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.cities_layout); WheelView country = (WheelView) findViewById(R.id.country); String countries[] = new String[] {"USA", "Canada", "Ukraine", "France"}; country.setVisibleItems(3); country.setAdapter(new ArrayWheelAdapter<String>(countries)); final String cities[][] = new String[][] { new String[] {"New York", "Washington", "Chicago", "Atlanta", "Orlando"}, new String[] {"Ottawa", "Vancouver", "Toronto", "Windsor", "Montreal"}, new String[] {"Kiev", "Dnipro", "Lviv", "Kharkiv"}, new String[] {"Paris", "Bordeaux"}, }; final WheelView city = (WheelView) findViewById(R.id.city); city.setVisibleItems(5); country.addChangingListener(new OnWheelChangedListener() { public void onChanged(WheelView wheel, int oldValue, int newValue) { city.setAdapter(new ArrayWheelAdapter<String>(cities[newValue])); city.setCurrentItem(cities[newValue].length / 2); } }); country.setCurrentItem(2); }
}</pre>轉自:http://blog.csdn.net/xyz_fly/article/details/7818288
</span>
本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!