上下滑动的滚动视图:
---------------------------------------------------------------------------------------------------------------------------------------------
可用来替换spinner下拉选框。
使用WheelView插件实现
WheelView插件包含这些,直接copy到项目对应位置即可:
Java类包括:,其中使用到两个drawable资源文件wheel_bg.xml和wheel_val.xml,内容分别为:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<gradient android:angle="90" android:centerColor="#ffdddddd" android:endColor="#ff333333" android:startColor="#ff333333" />
<stroke
android:width="1.0dip"
android:color="#ff333333" />
</shape>
</item>
<item
android:bottom="1.0dip"
android:left="4.0dip"
android:right="4.0dip"
android:top="1.0dip">
<shape android:shape="rectangle" >
<gradient
android:angle="90.0"
android:centerColor="#ffffffff"
android:endColor="#ffaaaaaa"
android:startColor="#ffaaaaaa" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90.0"
android:centerColor="#70222222"
android:endColor="#70eeeeee"
android:startColor="#70222222" />
<stroke
android:width="1.0dip"
android:color="#70333333" />
</shape>
可自己修改这两文件内容。
---------------------------------------------------------------------------------------------
接下来使用WheelView,
首先布局文件中加入控件:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="3"
android:background="@android:color/transparent"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<com.mywork.wheel.WheelView
android:id="@+id/provinceCode"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="145dp" >
</com.mywork.wheel.WheelView>
<com.mywork.wheel.WheelView
android:id="@+id/cityCode"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="145dp"
>
</com.mywork.wheel.WheelView>
</LinearLayout>
接着在布局文件对应的Activity中:
private String[] provinceCodes = {"川", "京", "渝", "沪", "津", "黑", "吉", "辽", "蒙", "冀", "新", "甘", "青", "陕", "宁", "豫", "鲁", "晋", "皖", "鄂", "湘", "苏", "黔", "滇", "桂", "藏", "浙", "赣", "粤", "闽", "台", "琼", "港", "澳"};
private String[] cityCodes = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cart_query);
RadioGroup cartTypeRadio = (RadioGroup)findViewById(R.id.cartTypeRadio);
cartTypeRadio.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int radioId) {
//TODO...
}
});
Button queryButton = (Button) findViewById(R.id.queryButton);
queryButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View paramView) {
Intent intent = new Intent(CartQuery.this, CartDetails.class);
CartQuery.this.startActivity(intent);
}
});
WheelView provinceCode = (WheelView) findViewById(R.id.provinceCode);
provinceCode.setCyclic(true);
provinceCode.setViewAdapter(new ArrayWheelAdapter<String>(this, provinceCodes));
WheelView ciryCode = (WheelView)findViewById(R.id.cityCode);
ciryCode.setCyclic(true);
ciryCode.setViewAdapter(new ArrayWheelAdapter<String>(this, cityCodes));
}
......
最简单的WheelView滑动滚动视图实现了
---------------------
不求鼓掌,只求勿喷