【Android】 横向纵向滚轮控件

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

    纵向滚轮控件:AndroidWheelDemoAndroidWheel

    

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

    

纵向滚轮控件如下:        

 

 

修改滚轮控件的布局可以在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">
    <!-- 背景效果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>

 

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值