Android自定义控件之天气视图

Github传送门:https://github.com/zhouzhuo810/ZzWeatherView
(欢迎start!)

(2017/3/13 修复了曲线不圆滑问题)

Gradle

compile 'me.zhouzhuo.zzweatherview:zz-weather-view:1.0.2'

效果图如下:

zz-weather-view-demo.jpg
zz-weather-view-demo_disc.jpg

用法简介:

1)布局

drawable/scroll_bar_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#33999999" android:endColor="#80aaaaaa"
        android:angle="0"/>
    <corners android:radius="6dp" />
</shape>
    <me.zhouzhuo.zzweatherview.ZzWeatherView
        android:id="@+id/weather_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbarThumbHorizontal="@drawable/scroll_bar_thumb"
        android:scrollbarTrackHorizontal="@drawable/scroll_bar_thumb"
        android:scrollbarSize="4dp"
        android:background="#333"
        >
    </me.zhouzhuo.zzweatherview.ZzWeatherView>

2)java

        ZzWeatherView weatherView = (ZzWeatherView) findViewById(R.id.weather_view);

        //填充天气数据
        weatherView.setList(generateData());

        //画折线
        weatherView.setLineType(ZzWeatherView.LINE_TYPE_DISCOUNT);
        //画曲线(不够圆滑希望有更好的建议联系我(Email:admin@zhouzhuo810.me))
        //weatherView.setLineType(ZzWeatherView.LINE_TYPE_CURVE);

        //设置线宽
        weatherView.setLineWidth(6f);

        //点击某一列
        weatherView.setOnWeatherItemClickListener(new ZzWeatherView.OnWeatherItemClickListener() {
            @Override
            public void onItemClick(WeatherItemView itemView, int position, WeatherModel weatherModel) {
                Toast.makeText(MainActivity.this, position+"", Toast.LENGTH_SHORT).show();
            }
        });
    //数据源
  WeatherModel model = new WeatherModel();
        model.setDate("12/07");//日期
        model.setWeek("昨天");  //星期
        model.setDayWeather("大雪"); //白天天气
        model.setDayTemp(11); //白天温度
        model.setNightTemp(5); //夜晚温度
        model.setNightWeather("晴"); //夜晚天气
        model.setWindOrientation("西南风"); //风向
        model.setWindLevel("3级"); //
        model.setAirLevel(AirLevel.EXCELLENT); //空气质量

玩安卓版王者荣耀的朋友,刷金币看这里
链接:http://pan.baidu.com/s/1gfKIeh9
辅助群:171977523

需要写安卓程序的小伙伴请关注我的淘宝店铺:
小周来帮您

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,955评论 2 45
  • 短发剪了快2年了吧 要不还是再留长吧 当年我也是个长发及臀的人呢 今天是今年最后一场《如梦之梦》了 不造现场有没有...
    咸酥阅读 139评论 0 0
  • 这是什么啊
    超级无敌思仔阅读 250评论 0 0
  • “跟你妈说说,今年能不能把奶奶接到我们家里过年?” “如果老妈问起是不是你的意思,我该怎么回答?” “你千万不要提...
    戒嗔阅读 11,487评论 1 2

友情链接更多精彩内容