android:background=“@mipmap/icon_100”
android:layout_width=“30dp”
android:layout_height=“30dp”/>
<LinearLayout
android:gravity=“right”
android:layout_width=“@dimen/dp_0”
android:layout_height=“wrap_content”
android:layout_weight=“1”>
<TextView
android:id=“@+id/tv_temp_height”
android:textSize=“@dimen/sp_14”
android:textColor=“#FFF”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
<TextView
android:id=“@+id/tv_temp_low”
android:textSize=“@dimen/sp_14”
android:textColor=“@color/temp_min_tx”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
就是把里面的溫度地段改成了兩個,用不同的顏色區(qū)分開,然后進(jìn)入DailyAdapter
照著這個截圖上面的修改就可以了,方法應(yīng)該是都有的。
最后在渲染數(shù)據(jù)的時候增加動畫
我在天氣預(yù)報的返回和逐小時天氣的返回數(shù)據(jù)中做了動畫的渲染,注意到用了兩個不同的動畫,一個是底部往上彈,一個是從右往左彈。
運(yùn)行之后效果如下
這樣看起來可能舒服一些吧,
二、更多空氣質(zhì)量數(shù)據(jù)展示
下面就要開始寫更多空氣質(zhì)量的頁面展示了。
老樣子,在app的ui包下新建一個MoreAirActivity,然后修改布局
,在修改之前我們先寫一個自定義View,這當(dāng)然也是需要樣式的
在mvplibrary的styles.xml中新增一個樣式
然后在mvplibrary的view包中新建一個LineProgressbar,代碼如下:
package com.llw.mvplibrary.view;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import com.llw.mvplibrary.R;
public class LineProgressbar extends View {
private Paint mPaint;//畫筆
private float mPaintWidth = 6f;//初始畫筆寬度
private int mProgressbarWidth;//控件外邊框?qū)挾?/p>
private int mProgressbarHeight;//控件外邊框高度
private int mPercent = 0;//已轉(zhuǎn)化為0至100范圍的當(dāng)前進(jìn)度,隨動畫時間改變而改變
public LineProgressbar(Context context) {
super(context);
}
@SuppressLint(“Recycle”)
public LineProgressbar(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.LineProgressbar);
mProgressbarWidth = (int) array.getDimension(R.styleable.LineProgressbar_progressbar_width, 100);
mProgressbarHeight = (int) array.getDimension(R.styleable.LineProgressbar_progressbar_height, 10);
}
public LineProgressbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(mProgressbarWidth, mProgressbarHeight);
}
@Override
@SuppressLint(“DrawAllocation”)
protected void onDraw(Canvas canvas) {
mPaint = new Paint();
//繪制背景
mPaint.setColor(getResources().getColor(R.color.arc_bg_color));
mPaint.setStyle(Paint.Style.FILL);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(mPaintWidth);
RectF frameRectF = new RectF(mPaintWidth, mPaintWidth, mProgressbarWidth - mPaintWidth, mProgressbarHeight - mPaintWidth);
canvas.drawRoundRect(frameRectF, 15, 15, mPaint);
//填充內(nèi)部進(jìn)度
mPaint.setPathEffect(null);
mPaint.setColor(Color.WHITE);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setAntiAlias(true);
//內(nèi)部進(jìn)度填充長度,隨動畫時間改變而改變
float percent = (float) mPercent / 100f;
RectF progressRectF = new RectF(mPaintWidth, mPaintWidth, mPaintWidth + percent * (mProgressbarWidth - 2 * mPaintWidth - 2), mProgressbarHeight - mPaintWidth);
canvas.drawRoundRect(progressRectF, 15, 15, mPaint);
}
public void setProgress(String progress, int maxProgress) {
int percent = 0;
//得出當(dāng)前progress占最大進(jìn)度值百分比(0-100)
if (progress.contains(“.”)) {//float或者double類型
percent = ((int) Float.parseFloat(progress) * 10) * 100 / (maxProgress * 10);
} else {//int類型
percent = Integer.parseInt(progress) * 100 / maxProgress;
}
if (percent < 0) {
percent = 0;
}
if (percent > 100) {
percent = 100;
}
//屬性動畫
ValueAnimator animator = ValueAnimator.ofInt(0, percent);
animator.setDuration(1000);
animator.setInterpolator(new AccelerateInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mPercent = (int) valueAnimator.getAnimatedValue();
invalidate();
}
});
animator.start();
}
}
現(xiàn)在可以看布局文件activity_more_air.xml了,代碼如下:
里面用到的背景圖片
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@drawable/more_air_bg”
android:fitsSystemWindows=“true”
android:orientation=“vertical”
tools:context=“.ui.MoreAirActivity”>
<androidx.appcompat.widget.Toolbar
android:id=“@+id/toolbar”
android:layout_width=“match_parent”
android:layout_height=“?attr/actionBarSize”
app:contentInsetLeft=“@dimen/dp_16”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintLeft_toLeftOf=“parent”
app:layout_constraintTop_toTopOf=“parent”
app:navigationIcon=“@mipmap/icon_return_white”
app:popupTheme=“@style/AppTheme.PopupOverlay”>
<TextView
android:id=“@+id/tv_title”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center”
android:text=“更多空氣質(zhì)量”
android:textColor=“@color/white”
android:textSize=“@dimen/sp_16” />
</androidx.appcompat.widget.Toolbar>
<androidx.core.widget.NestedScrollView
android:overScrollMode=“never”
android:layout_width=“match_parent”
android:layout_height=“match_parent”>
<LinearLayout
android:orientation=“vertical”
android:layout_width=“match_parent”
android:layout_height=“match_parent”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_margin=“@dimen/dp_12”
android:background=“@drawable/shape_transparent_12”
android:orientation=“vertical”
android:padding=“@dimen/dp_12”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“實時空氣質(zhì)量”
android:textColor=“@color/white”
android:textSize=“@dimen/sp_16” />
<TextView
android:id=“@+id/tv_old_time”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“right”
android:text=“上次更新時間:”
android:textColor=“@color/white”
android:textSize=“@dimen/sp_12” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“@dimen/dp_12”>
<LinearLayout
android:layout_width=“0dp”
android:layout_height=“match_parent”
android:layout_weight=“1”
android:gravity=“center”
android:orientation=“vertical”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginBottom=“8dp”
android:text=“污染指數(shù)”
android:textColor=“#DAEBEE”
android:textSize=“14sp” />
<com.llw.mvplibrary.view.RoundProgressBar
android:id=“@+id/rpb_aqi”
android:layout_width=“120dp”
android:layout_height=“120dp”
android:layout_gravity=“center”
app:round_bg_color=“#C6D7F4”
app:round_progress_color=“#FBFEF7” />
<LinearLayout
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:orientation=“vertical”>
<LinearLayout
android:gravity=“center_vertical”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”>
<TextView
android:layout_width=“@dimen/dp_44”
android:layout_height=“wrap_content”
android:gravity=“center”
android:text=“PM10”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<com.llw.mvplibrary.view.LineProgressbar
android:id=“@+id/progress_pm10”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center”
app:progressbar_width=“@dimen/dp_80”
app:progressbar_height=“@dimen/dp_10”/>
<TextView
android:id=“@+id/tv_pm10”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:gravity=“center_vertical”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<TextView
android:layout_width=“@dimen/dp_44”
android:layout_height=“wrap_content”
android:gravity=“center”
android:text=“PM2.5”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<com.llw.mvplibrary.view.LineProgressbar
android:id=“@+id/progress_pm25”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center”
app:progressbar_width=“@dimen/dp_80”
app:progressbar_height=“@dimen/dp_10”/>
<TextView
android:id=“@+id/tv_pm25”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:gravity=“center_vertical”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<LinearLayout
android:layout_width=“@dimen/dp_44”
android:layout_height=“wrap_content”
android:gravity=“center”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“NO”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“2”
android:textColor=“@color/blue_one”
android:textSize=“8sp” />
<com.llw.mvplibrary.view.LineProgressbar
android:id=“@+id/progress_no2”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center”
app:progressbar_width=“@dimen/dp_80”
app:progressbar_height=“@dimen/dp_10”/>
<TextView
android:id=“@+id/tv_no2”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:gravity=“center_vertical”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<LinearLayout
android:layout_width=“@dimen/dp_44”
android:layout_height=“wrap_content”
android:gravity=“center”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“SO”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“2”
android:textColor=“@color/blue_one”
android:textSize=“8sp” />
<com.llw.mvplibrary.view.LineProgressbar
android:id=“@+id/progress_so2”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center”
app:progressbar_width=“@dimen/dp_80”
app:progressbar_height=“@dimen/dp_10”/>
<TextView
android:id=“@+id/tv_so2”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:gravity=“center_vertical”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<LinearLayout
android:layout_width=“@dimen/dp_44”
android:layout_height=“wrap_content”
android:gravity=“center”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“O”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“3”
android:textColor=“@color/blue_one”
android:textSize=“8sp” />
<com.llw.mvplibrary.view.LineProgressbar
android:id=“@+id/progress_o3”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center”
app:progressbar_width=“@dimen/dp_80”
app:progressbar_height=“@dimen/dp_10”/>
<TextView
android:id=“@+id/tv_o3”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:gravity=“center_vertical”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<TextView
android:layout_width=“@dimen/dp_44”
android:layout_height=“wrap_content”
android:gravity=“center”
android:text=“CO”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<com.llw.mvplibrary.view.LineProgressbar
android:id=“@+id/progress_co”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center”
app:progressbar_width=“@dimen/dp_80”
app:progressbar_height=“@dimen/dp_10”/>
<TextView
android:id=“@+id/tv_co”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<TextView
android:layout_marginLeft=“@dimen/dp_12”
android:text=“監(jiān)測站空氣質(zhì)量”
android:textColor=“@color/white”
android:textSize=“@dimen/sp_16”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
<androidx.recyclerview.widget.RecyclerView
android:id=“@+id/rv_station”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:overScrollMode=“never” />
<TextView
android:layout_marginLeft=“@dimen/dp_12”
android:text=“未來5天空氣質(zhì)量預(yù)報”
android:textColor=“@color/white”
android:textSize=“@dimen/sp_16”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
<androidx.recyclerview.widget.RecyclerView
android:id=“@+id/rv_five_air”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginBottom=“@dimen/dp_12”
android:overScrollMode=“never” />
</androidx.core.widget.NestedScrollView>
現(xiàn)在可以創(chuàng)建item的布局文件里,這里面有兩個列表,自然就需要兩個item的布局,
先來看第一個的布局,在layout下新建一個item_more_air_station_list.xml,這個用于展示檢測站的空氣質(zhì)量。代碼如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“vertical”
android:padding=“@dimen/dp_12”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@drawable/shape_transparent_12”
android:gravity=“center_horizontal”
android:orientation=“vertical”
android:padding=“@dimen/dp_12”>
<TextView
android:id=“@+id/tv_station_name”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:textColor=“@color/white”
android:textSize=“@dimen/sp_18” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“@dimen/dp_20”
android:orientation=“vertical”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“horizontal”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“空氣質(zhì)量”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_air_category”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“@dimen/dp_12”
android:orientation=“horizontal”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“空氣質(zhì)量指數(shù)”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_aqi”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“@dimen/dp_12”
android:orientation=“horizontal”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“主要污染物”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_primary”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“PM10”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_pm10”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“PM2.5”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_pm25”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“二氧化氮”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_no2”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“二氧化硫”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_so2”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“一氧化碳”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_o3”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginTop=“12dp”>
<TextView
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:text=“臭氧”
android:textColor=“@color/blue_one”
android:textSize=“12sp” />
<TextView
android:id=“@+id/tv_co”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:textColor=“@color/white”
android:textSize=“12sp” />
比較的簡單,下面在layout下創(chuàng)建item_more_air_five_list.xml,用于展示當(dāng)前城市未來五天的空氣質(zhì)量預(yù)報。布局如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:orientation=“vertical”
android:padding=“@dimen/dp_12”>
<LinearLayout
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:background=“@drawable/shape_transparent_12”
android:gravity=“center_horizontal”
android:orientation=“vertical”
android:padding=“@dimen/dp_12”>
<LinearLayout
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:gravity=“center”
android:orientation=“vertical”>
<TextView
android:id=“@+id/tv_date_info”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:textColor=“@color/white”
android:textSize=“@dimen/sp_18” />
<TextView
android:id=“@+id/tv_date”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:textColor=“@color/white”
android:textSize=“@dimen/sp_14” />
<LinearLayout
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“AQI指數(shù)”
android:textColor=“@color/white” />
<TextView
android:id=“@+id/tv_aqi”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginLeft=“@dimen/dp_20”
android:text=“空氣質(zhì)量”
android:textColor=“@color/white” />
<LinearLayout
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginTop=“@dimen/dp_4”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“空氣質(zhì)量”
android:textColor=“@color/white” />
<TextView
android:id=“@+id/tv_category”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginLeft=“@dimen/dp_20”
android:text=“空氣質(zhì)量”
android:textColor=“@color/white” />
<LinearLayout
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginTop=“@dimen/dp_4”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“污染物”
android:textColor=“@color/white” />
<TextView
android:id=“@+id/tv_primary”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginLeft=“@dimen/dp_20”
android:text=“空氣質(zhì)量”
android:textColor=“@color/white” />
因為這個查詢多天的空氣質(zhì)量之前并沒有寫上去,所以要在ApiService中新增一個,同時需要在app的bean包下面新建一個數(shù)據(jù)實體MoreAirFiveResponse,代碼如下:
package com.llw.goodweather.bean;
import java.util.List;
public class MoreAirFiveResponse {
/**
-
code : 200
-
updateTime : 2020-08-06T09:28+08:00
-
fxLink : http://hfx.link/2ax4
-
daily : [{“fxDate”:“2020-08-06”,“aqi”:“60”,“l(fā)evel”:“2”,“category”:“良”,“primary”:“NA”},{“fxDate”:“2020-08-07”,“aqi”:“90”,“l(fā)evel”:“2”,“category”:“良”,“primary”:“NA”},{“fxDate”:“2020-08-08”,“aqi”:“100”,“l(fā)evel”:“2”,“category”:“良”,“primary”:“NA”},{“fxDate”:“2020-08-09”,“aqi”:“110”,“l(fā)evel”:“3”,“category”:“輕度污染”,“primary”:“NA”},{“fxDate”:“2020-08-10”,“aqi”:“90”,“l(fā)evel”:“2”,“category”:“良”,“primary”:“NA”}]
-
refer : {“sources”:[“cnemc”],“l(fā)icense”:[“no commercial use”]}
*/
private String code;
private String updateTime;
private String fxLink;
private ReferBean refer;
private List daily;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public String getFxLink() {
return fxLink;
}
public void setFxLink(String fxLink) {
this.fxLink = fxLink;
}
public ReferBean getRefer() {
return refer;
}
public void setRefer(ReferBean refer) {
this.refer = refer;
}
public List getDaily() {
return daily;
}
public void setDaily(List daily) {
this.daily = daily;
}
public static class ReferBean {
private List sources;
private List license;
public List getSources() {
return sources;
}
public void setSources(List sources) {
this.sources = sources;
}
public List getLicense() {
return license;
}
public void setLicense(List license) {
this.license = license;
}
}
public static class DailyBean {
/**
-
fxDate : 2020-08-06
-
aqi : 60
-
level : 2
-
category : 良
-
primary : NA
*/
private String fxDate;
private String aqi;
private String level;
private String category;
private String primary;
public String getFxDate() {
return fxDate;
}
public void setFxDate(String fxDate) {
this.fxDate = fxDate;
}
public String getAqi() {
return aqi;
}
public void setAqi(String aqi) {
this.aqi = aqi;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getPrimary() {
return primary;
}
public void setPrimary(String primary) {
this.primary = primary;
}
}
}
ApiService中新增如下接口
/**
-
空氣質(zhì)量5天預(yù)報
-
@param location 城市id
-
@return 返回空氣質(zhì)量5天預(yù)報數(shù)據(jù)
*/
@GET(“/v7/air/5d?key=3086e91d66c04ce588a7f538f917c7f4”)
Call airFiveWeather(@Query(“l(fā)ocation”) String location);
現(xiàn)在可以創(chuàng)建一個新的訂閱器了,在app的contract包下新建一個MoreAirContract,代碼如下:
package com.llw.goodweather.contract;
import com.llw.goodweather.api.ApiService;
import com.llw.goodweather.bean.AirNowResponse;
import com.llw.goodweather.bean.DailyResponse;
import com.llw.goodweather.bean.MoreAirFiveResponse;
import com.llw.goodweather.bean.NewSearchCityResponse;
import com.llw.mvplibrary.base.BasePresenter;
import com.llw.mvplibrary.base.BaseView;
import com.llw.mvplibrary.net.NetCallBack;
import com.llw.mvplibrary.net.ServiceGenerator;
import retrofit2.Call;
import retrofit2.Response;
/**
- 更多空氣質(zhì)量數(shù)據(jù)訂閱器
*/
public class MoreAirContract {
public static class MoreAirPresenter extends BasePresenter {
/**
-
搜索城市 搜索站點的城市id,用于查詢空氣質(zhì)量
-
@param location 城市名
*/
public void searchCityId(String location) {//注意這里的4表示新的搜索城市地址接口
ApiService service = ServiceGenerator.createService(ApiService.class, 4);//指明訪問的地址
service.newSearchCity(location,“exact”).enqueue(new NetCallBack() {
@Override
public void onSuccess(Call call, Response response) {
if(getView() != null){
getView().getSearchCityIdResult(response);
}
}
@Override
public void onFailed() {
if(getView() != null){
getView().getDataFailed();
}
}
});
}
/**
-
空氣質(zhì)量 V7
-
@param location 城市id
*/
public void air(String location) {
ApiService service = ServiceGenerator.createService(ApiService.class,3);
service.airNowWeather(location).enqueue(new NetCallBack() {
@Override
public void onSuccess(Call call, Response response) {
if(getView() != null){
getView().getMoreAirResult(response);
}
}
@Override
public void onFailed() {
if(getView() != null){
getView().getDataFailed();
}
}
});
}
/**
-
五天空氣質(zhì)量數(shù)據(jù) V7
-
@param location 城市id
*/
public void airFive(String location) {
ApiService service = ServiceGenerator.createService(ApiService.class,3);
service.airFiveWeather(location).enqueue(new NetCallBack() {
@Override
public void onSuccess(Call call, Response response) {
if(getView() != null){
getView().getMoreAirFiveResult(response);
}
}
@Override
public void onFailed() {
if(getView() != null){
getView().getDataFailed();
}
}
});
}
}
public interface IMoreAirView extends BaseView {
//搜索城市Id
void getSearchCityIdResult(Response response);
//空氣質(zhì)量返回數(shù)據(jù) V7
自我介紹一下,小編13年上海交大畢業(yè),曾經(jīng)在小公司待過,也去過華為、OPPO等大廠,18年進(jìn)入阿里一直到現(xiàn)在。
深知大多數(shù)Android工程師,想要提升技能,往往是自己摸索成長或者是報班學(xué)習(xí),但對于培訓(xùn)機(jī)構(gòu)動則幾千的學(xué)費,著實壓力不小。自己不成體系的自學(xué)效果低效又漫長,而且極易碰到天花板技術(shù)停滯不前!
因此收集整理了一份《2024年Android移動開發(fā)全套學(xué)習(xí)資料》,初衷也很簡單,就是希望能夠幫助到想自學(xué)提升又不知道該從何學(xué)起的朋友,同時減輕大家的負(fù)擔(dān)。
既有適合小白學(xué)習(xí)的零基礎(chǔ)資料,也有適合3年以上經(jīng)驗的小伙伴深入學(xué)習(xí)提升的進(jìn)階課程,基本涵蓋了95%以上Android開發(fā)知識點,真正體系化!
由于文件比較大,這里只是將部分目錄大綱截圖出來,每個節(jié)點里面都包含大廠面經(jīng)、學(xué)習(xí)筆記、源碼講義、實戰(zhàn)項目、講解視頻,并且后續(xù)會持續(xù)更新
如果你覺得這些內(nèi)容對你有幫助,可以添加V獲?。簐ip204888 (備注Android)
總結(jié)
最后為了幫助大家深刻理解Android相關(guān)知識點的原理以及面試相關(guān)知識,這里放上相關(guān)的我搜集整理的14套騰訊、字節(jié)跳動、阿里、百度等2021最新面試真題解析,我把技術(shù)點整理成了視頻和PDF(實際上比預(yù)期多花了不少精力),包知識脈絡(luò) + 諸多細(xì)節(jié)。
網(wǎng)上學(xué)習(xí) Android的資料一大堆,但如果學(xué)到的知識不成體系,遇到問題時只是淺嘗輒止,不再深入研究,那么很難做到真正的技術(shù)提升。
本文已被CODING開源項目:《Android學(xué)習(xí)筆記總結(jié)+移動架構(gòu)視頻+大廠面試真題+項目實戰(zhàn)源碼》收錄
一個人可以走的很快,但一群人才能走的更遠(yuǎn)。如果你從事以下工作或?qū)σ韵赂信d趣,歡迎戳這里加入程序員的圈子,讓我們一起學(xué)習(xí)成長!文章來源:http://www.zghlxwxcb.cn/news/detail-845718.html
AI人工智能、Android移動開發(fā)、AIGC大模型、C C#、Go語言、Java、Linux運(yùn)維、云計算、MySQL、PMP、網(wǎng)絡(luò)安全、Python爬蟲、UE5、UI設(shè)計、Unity3D、Web前端開發(fā)、產(chǎn)品經(jīng)理、車載開發(fā)、大數(shù)據(jù)、鴻蒙、計算機(jī)網(wǎng)絡(luò)、嵌入式物聯(lián)網(wǎng)、軟件測試、數(shù)據(jù)結(jié)構(gòu)與算法、音視頻開發(fā)、Flutter、IOS開發(fā)、PHP開發(fā)、.NET、安卓逆向、云計算文章來源地址http://www.zghlxwxcb.cn/news/detail-845718.html
taFailed();
}
}
});
}
/**
-
五天空氣質(zhì)量數(shù)據(jù) V7
-
@param location 城市id
*/
public void airFive(String location) {
ApiService service = ServiceGenerator.createService(ApiService.class,3);
service.airFiveWeather(location).enqueue(new NetCallBack() {
@Override
public void onSuccess(Call call, Response response) {
if(getView() != null){
getView().getMoreAirFiveResult(response);
}
}
@Override
public void onFailed() {
if(getView() != null){
getView().getDataFailed();
}
}
});
}
}
public interface IMoreAirView extends BaseView {
//搜索城市Id
void getSearchCityIdResult(Response response);
//空氣質(zhì)量返回數(shù)據(jù) V7
自我介紹一下,小編13年上海交大畢業(yè),曾經(jīng)在小公司待過,也去過華為、OPPO等大廠,18年進(jìn)入阿里一直到現(xiàn)在。
深知大多數(shù)Android工程師,想要提升技能,往往是自己摸索成長或者是報班學(xué)習(xí),但對于培訓(xùn)機(jī)構(gòu)動則幾千的學(xué)費,著實壓力不小。自己不成體系的自學(xué)效果低效又漫長,而且極易碰到天花板技術(shù)停滯不前!
因此收集整理了一份《2024年Android移動開發(fā)全套學(xué)習(xí)資料》,初衷也很簡單,就是希望能夠幫助到想自學(xué)提升又不知道該從何學(xué)起的朋友,同時減輕大家的負(fù)擔(dān)。
[外鏈圖片轉(zhuǎn)存中…(img-Nl114m1B-1712146775355)]
[外鏈圖片轉(zhuǎn)存中…(img-Og2d8Ppm-1712146775355)]
[外鏈圖片轉(zhuǎn)存中…(img-y2Wvgq4y-1712146775356)]
[外鏈圖片轉(zhuǎn)存中…(img-fPSJJcYq-1712146775356)]
[外鏈圖片轉(zhuǎn)存中…(img-rlzkj4yA-1712146775356)]
[外鏈圖片轉(zhuǎn)存中…(img-4yDwTbdx-1712146775357)]
既有適合小白學(xué)習(xí)的零基礎(chǔ)資料,也有適合3年以上經(jīng)驗的小伙伴深入學(xué)習(xí)提升的進(jìn)階課程,基本涵蓋了95%以上Android開發(fā)知識點,真正體系化!
由于文件比較大,這里只是將部分目錄大綱截圖出來,每個節(jié)點里面都包含大廠面經(jīng)、學(xué)習(xí)筆記、源碼講義、實戰(zhàn)項目、講解視頻,并且后續(xù)會持續(xù)更新
如果你覺得這些內(nèi)容對你有幫助,可以添加V獲?。簐ip204888 (備注Android)
[外鏈圖片轉(zhuǎn)存中…(img-fKjpB2eN-1712146775357)]
總結(jié)
最后為了幫助大家深刻理解Android相關(guān)知識點的原理以及面試相關(guān)知識,這里放上相關(guān)的我搜集整理的14套騰訊、字節(jié)跳動、阿里、百度等2021最新面試真題解析,我把技術(shù)點整理成了視頻和PDF(實際上比預(yù)期多花了不少精力),包知識脈絡(luò) + 諸多細(xì)節(jié)。
[外鏈圖片轉(zhuǎn)存中…(img-vZaDN2ov-1712146775357)]
[外鏈圖片轉(zhuǎn)存中…(img-qcW8X11g-1712146775357)]
[外鏈圖片轉(zhuǎn)存中…(img-pOypNa0I-1712146775358)]
[外鏈圖片轉(zhuǎn)存中…(img-B6uTUF5B-1712146775358)]
網(wǎng)上學(xué)習(xí) Android的資料一大堆,但如果學(xué)到的知識不成體系,遇到問題時只是淺嘗輒止,不再深入研究,那么很難做到真正的技術(shù)提升。
本文已被CODING開源項目:《Android學(xué)習(xí)筆記總結(jié)+移動架構(gòu)視頻+大廠面試真題+項目實戰(zhàn)源碼》收錄
一個人可以走的很快,但一群人才能走的更遠(yuǎn)。如果你從事以下工作或?qū)σ韵赂信d趣,歡迎戳這里加入程序員的圈子,讓我們一起學(xué)習(xí)成長!
AI人工智能、Android移動開發(fā)、AIGC大模型、C C#、Go語言、Java、Linux運(yùn)維、云計算、MySQL、PMP、網(wǎng)絡(luò)安全、Python爬蟲、UE5、UI設(shè)計、Unity3D、Web前端開發(fā)、產(chǎn)品經(jīng)理、車載開發(fā)、大數(shù)據(jù)、鴻蒙、計算機(jī)網(wǎng)絡(luò)、嵌入式物聯(lián)網(wǎng)、軟件測試、數(shù)據(jù)結(jié)構(gòu)與算法、音視頻開發(fā)、Flutter、IOS開發(fā)、PHP開發(fā)、.NET、安卓逆向、云計算
到了這里,關(guān)于Android 天氣APP(二十二)改動些許UI、增加更多空氣質(zhì)量數(shù)據(jù)和生活建議數(shù)據(jù)展示的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!