【Android】 横向纵向滚轮控件

项目需要纵向滚轮控件和横向滚轮控件

    纵向滚轮控件:AndroidWheelDemo、AndroidWheel

    【Android】 横向纵向滚轮控件_第1张图片

    横向滚轮控件:android 滚轮刻度尺的实现、android自己写的类似刻度尺的东西。

    【Android】 横向纵向滚轮控件_第2张图片

纵向滚轮控件如下:        

【Android】 横向纵向滚轮控件_第3张图片

 

 

修改滚轮控件的布局可以在src/kankan/wheel/widget/WheelView.java和/res/drawable/wheel_val.xml

                                      和/res/layout/wheel_text_item.xml和\res\layout\tempitem.xml和src\kankan\wheel\demo\CitiesActivity.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">
    
    <item>
         
        <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>
    
    <item android:left="4dp" android:right="4dp" android:top="1dp" android:bottom="1dp">
         
        <shape android:shape="rectangle">
            
            <gradient
                android:startColor="#FFFF33"
                android:centerColor="#FFFF33"
                android:endColor="#FFFF33"
                android:angle="90" />
        shape>
    item>
layer-list>

 

转载于:https://www.cnblogs.com/xubuhang/p/4255805.html

你可能感兴趣的:(【Android】 横向纵向滚轮控件)