Android自定义控件之天气视图

作者: zhouzhuo810 | 来源:发表于2017-01-13 13:36 被阅读1189次

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

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

相关文章

网友评论

  • d562abb50057:还有一个问题就是为什么有时候会2条曲线合成了一条直线,要向左滑动才会显示出来
    zhouzhuo810:@listercai 有图吗?
  • d562abb50057:java.lang.NoSuchFieldError: No field tv_week of type I in class Lme/zhouzhuo/zzweatherview/R$id; or its superclasses (declaration of 'me.zhouzhuo.zzweatherview.R$id' appears in /data/data/com.listercai.gaozhitianqi/files/instant-run/dex/slice-slice_9-classes.dex)

    楼主我用你的库冲突了,好像是xml的名字重复,导致找不到Id。google半天找不到答案,,能指导一下吗?
    d562abb50057:解决了,布局xml和你的库的某个xml重复了。谢谢
    zhouzhuo810:@listercai tv_week这个id在同一个布局里有出现么?
  • 480705090333:请问你的天气接口是什么天气,我能直接用上你的天气数据的吗
    zhouzhuo810:这是虚拟数据 没有用接口
  • 200ba7b7e6ac:不错不错

本文标题:Android自定义控件之天气视图

本文链接:https://www.haomeiwen.com/subject/fphsbttx.html