Android自定義控件之天氣視圖

Github傳送門:https://github.com/zhouzhuo810/ZzWeatherView
(歡迎start!)

(2017/3/13 修復(fù)了曲線不圓滑問題)

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);

        //填充天氣數(shù)據(jù)
        weatherView.setList(generateData());

        //畫折線
        weatherView.setLineType(ZzWeatherView.LINE_TYPE_DISCOUNT);
        //畫曲線(不夠圓滑希望有更好的建議聯(lián)系我(Email:admin@zhouzhuo810.me))
        //weatherView.setLineType(ZzWeatherView.LINE_TYPE_CURVE);

        //設(shè)置線寬
        weatherView.setLineWidth(6f);

        //點(diǎn)擊某一列
        weatherView.setOnWeatherItemClickListener(new ZzWeatherView.OnWeatherItemClickListener() {
            @Override
            public void onItemClick(WeatherItemView itemView, int position, WeatherModel weatherModel) {
                Toast.makeText(MainActivity.this, position+"", Toast.LENGTH_SHORT).show();
            }
        });
    //數(shù)據(jù)源
  WeatherModel model = new WeatherModel();
        model.setDate("12/07");//日期
        model.setWeek("昨天");  //星期
        model.setDayWeather("大雪"); //白天天氣
        model.setDayTemp(11); //白天溫度
        model.setNightTemp(5); //夜晚溫度
        model.setNightWeather("晴"); //夜晚天氣
        model.setWindOrientation("西南風(fēng)"); //風(fēng)向
        model.setWindLevel("3級(jí)"); //
        model.setAirLevel(AirLevel.EXCELLENT); //空氣質(zhì)量

玩安卓版王者榮耀的朋友,刷金幣看這里
鏈接:http://pan.baidu.com/s/1gfKIeh9
輔助群:171977523

需要寫安卓程序的小伙伴請關(guān)注我的淘寶店鋪:
小周來幫您

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,881評(píng)論 2 45
  • 短發(fā)剪了快2年了吧 要不還是再留長吧 當(dāng)年我也是個(gè)長發(fā)及臀的人呢 今天是今年最后一場《如夢之夢》了 不造現(xiàn)場有沒有...
    咸酥閱讀 134評(píng)論 0 0
  • 這是什么啊
    超級(jí)無敵思仔閱讀 247評(píng)論 0 0
  • “跟你媽說說,今年能不能把奶奶接到我們家里過年?” “如果老媽問起是不是你的意思,我該怎么回答?” “你千萬不要提...
    戒嗔閱讀 11,469評(píng)論 1 2

友情鏈接更多精彩內(nèi)容