【Android】 横向纵向滚轮控件
項目需要縱向滾輪控件和橫向滾輪控件
縱向滾輪控件: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/?
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。?
?
總結
以上是生活随笔為你收集整理的【Android】 横向纵向滚轮控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c# streamReader转XmlD
- 下一篇: 浏览器重定向(302)次数限制问题