项目需要纵向滚轮控件和横向滚轮控件
纵向滚轮控件:AndroidWheelDemo、AndroidWheel
横向滚轮控件:android 滚轮刻度尺的实现、android自己写的类似刻度尺的东西。
纵向滚轮控件如下:
修改滚轮控件的布局可以在src/kankan/wheel/widget/WheelView.java和/res/drawable/wheel_val.xml
和/res/layout/wheel_text_item.xml和eslayout empitem.xml和srckankanwheeldemoCitiesActivity.java
修改控件字体大小、颜色:
CitiesActivity.java
/** * Adapter for countries */ private class CountryAdapter extends AbstractWheelTextAdapter { // Countries names ArrayList list; protected CountryAdapter(Context context,ArrayList list) { super(context, R.layout.tempitem, NO_RESOURCE); this.list = list; setItemTextResource(R.id.tempValue); } // Countries flags private int flags =R.drawable.tem_unit_dialog; @Override public View getItem(int index, View cachedView, ViewGroup parent) { View view = super.getItem(index, cachedView, parent); ImageView img = (ImageView) view.findViewById(R.id.tempImag); img.setImageResource(flags); return view; } @Override public int getItemsCount() { return list.size(); } @Override protected CharSequence getItemText(int index) { return list.get(index)+""; } }
tempitem.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:gravity="center" > <TextView android:id="@+id/tempValue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="23dp" android:textColor="#ff6347" /> <ImageView android:id="@+id/tempImag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/tem_unit_dialog"/> </LinearLayout>
wheel_text_item.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20dp" android:lines="1" android:textStyle="bold" android:textColor="#FF111111" android:layout_gravity="right" />
修改控件布局、背景:WheelView.java和wheel_val.xml
wheel_val.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 当前项 --> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 背景的过渡色 --> <gradient android:startColor="#70222222" android:centerColor="#70222222" android:endColor="#70EEEEEE" android:angle="90" /> <!-- 分割线 --> <stroke android:width="1dp" android:color="#F0FF63" /> </shape>
wheel_bg.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 将多个图片或效果按照顺序层叠起来 --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 背景效果1 --> <item> <!--XML中定义的几何形状 --> <shape android:shape="rectangle"> <!-- 渐变 --> <gradient android:startColor="#33CC99" android:centerColor="#33CC99" android:endColor="#33CC99" android:angle="90" /> <!-- 描边 --><!-- 左右边缘线 --> <stroke android:width="1dp" android:color="#FF3399" /> </shape> </item> <!-- 背景效果2 --> <item android:left="4dp" android:right="4dp" android:top="1dp" android:bottom="1dp"> <!--XML中定义的几何形状 --> <shape android:shape="rectangle"> <!-- 渐变 --> <gradient android:startColor="#FFFF33" android:centerColor="#FFFF33" android:endColor="#FFFF33" android:angle="90" /> </shape> </item> </layer-list>
作者:xubuhang
出处:http://www.cnblogs.com/xubuhang/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。