Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示

这篇具有很好参考价值的文章主要介绍了Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

}

public void setTmp_min(String tmp_min) {

this.tmp_min = tmp_min;

}

public String getUv_index() {

return uv_index;

}

public void setUv_index(String uv_index) {

this.uv_index = uv_index;

}

public String getVis() {

return vis;

}

public void setVis(String vis) {

this.vis = vis;

}

public String getWind_deg() {

return wind_deg;

}

public void setWind_deg(String wind_deg) {

this.wind_deg = wind_deg;

}

public String getWind_dir() {

return wind_dir;

}

public void setWind_dir(String wind_dir) {

this.wind_dir = wind_dir;

}

public String getWind_sc() {

return wind_sc;

}

public void setWind_sc(String wind_sc) {

this.wind_sc = wind_sc;

}

public String getWind_spd() {

return wind_spd;

}

public void setWind_spd(String wind_spd) {

this.wind_spd = wind_spd;

}

}

public static class HourlyBean {

/**

  • cloud : 11

  • cond_code : 101

  • cond_txt : 多云

  • dew : 22

  • hum : 73

  • pop : 7

  • pres : 998

  • time : 2020-05-16 13:00

  • tmp : 33

  • wind_deg : 174

  • wind_dir : 南风

  • wind_sc : 1-2

  • wind_spd : 5

*/

private String cloud;

private String cond_code;

private String cond_txt;

private String dew;

private String hum;

private String pop;

private String pres;

private String time;

private String tmp;

private String wind_deg;

private String wind_dir;

private String wind_sc;

private String wind_spd;

public String getCloud() {

return cloud;

}

public void setCloud(String cloud) {

this.cloud = cloud;

}

public String getCond_code() {

return cond_code;

}

public void setCond_code(String cond_code) {

this.cond_code = cond_code;

}

public String getCond_txt() {

return cond_txt;

}

public void setCond_txt(String cond_txt) {

this.cond_txt = cond_txt;

}

public String getDew() {

return dew;

}

public void setDew(String dew) {

this.dew = dew;

}

public String getHum() {

return hum;

}

public void setHum(String hum) {

this.hum = hum;

}

public String getPop() {

return pop;

}

public void setPop(String pop) {

this.pop = pop;

}

public String getPres() {

return pres;

}

public void setPres(String pres) {

this.pres = pres;

}

public String getTime() {

return time;

}

public void setTime(String time) {

this.time = time;

}

public String getTmp() {

return tmp;

}

public void setTmp(String tmp) {

this.tmp = tmp;

}

public String getWind_deg() {

return wind_deg;

}

public void setWind_deg(String wind_deg) {

this.wind_deg = wind_deg;

}

public String getWind_dir() {

return wind_dir;

}

public void setWind_dir(String wind_dir) {

this.wind_dir = wind_dir;

}

public String getWind_sc() {

return wind_sc;

}

public void setWind_sc(String wind_sc) {

this.wind_sc = wind_sc;

}

public String getWind_spd() {

return wind_spd;

}

public void setWind_spd(String wind_spd) {

this.wind_spd = wind_spd;

}

}

public static class LifestyleBean {

/**

  • type : comf

  • brf : 较不舒适

  • txt : 白天天气多云,并且空气湿度偏大,在这种天气条件下,您会感到有些闷热,不很舒适。

*/

private String type;

private String brf;

private String txt;

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public String getBrf() {

return brf;

}

public void setBrf(String brf) {

this.brf = brf;

}

public String getTxt() {

return txt;

}

public void setTxt(String txt) {

this.txt = txt;

}

}

}

}

在ApiService中增加

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

/**

  • 获取所有天气数据,在返回值中再做处理

  • @param location

  • @return

*/

@GET(“/s6/weather?key=3086e91d66c04ce588a7f538f917c7f4”)

Call weatherData(@Query(“location”) String location);

在WeatherContract中增加订阅

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

/**

  • 天气所有数据

  • @param context

  • @param location

*/

public void weatherData(final Context context,String location){

ApiService service = ServiceGenerator.createService(ApiService.class,0);

service.weatherData(location).enqueue(new NetCallBack() {

@Override

public void onSuccess(Call call, Response response) {

if(getView() != null){

getView().getWeatherDataResult(response);

}

}

@Override

public void onFailed() {

if(getView() != null){

getView().getWeatherDataFailed();

}

}

});

}

//查询天气所有数据

void getWeatherDataResult(Response response);

//天气数据获取错误返回

void getWeatherDataFailed();

进入MainActivity.java中

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

/**

  • 所有天气数据返回

  • @param response

*/

@Override

public void getWeatherDataResult(Response response) {

dismissLoadingDialog();//关闭弹窗

if ((“ok”).equals(response.body().getHeWeather6().get(0).getStatus())) {

}else {

ToastUtils.showShortToast(context, CodeToStringUtils.WeatherCode(response.body().getHeWeather6().get(0).getStatus()));

}

}

首先改动适配器

七天天气预报适配器WeatherForecastAdapter.java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

逐小时天气预报适配器WeatherHourlyAdapter.java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

然后回到MainActivity.java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

红框中为新增的,然后之前的注释掉,当所有的改动都完成之后,再删除掉注释的没有用的代码、

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

红框中的就是你要改动的

然后修改切换城市之后的方法请求

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

定位后

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

下拉刷新之后

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

onResume方法中

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

返回值里面的业务逻辑处理代码先注释掉,最后修改getWeatherDataResult。

修改代码如下:

/**

  • 所有天气数据返回

  • @param response

*/

@Override

public void getWeatherDataResult(Response response) {

refresh.finishRefresh();//关闭刷新

dismissLoadingDialog();//关闭弹窗

if (mLocationClient != null) {

mLocationClient.stop();//数据返回后关闭定位

}

if ((“ok”).equals(response.body().getHeWeather6().get(0).getStatus())) {

if (response.body().getHeWeather6().get(0).getBasic() != null) {//得到数据不为空则进行数据显示

/**

  • 当天天气

*/

tvTemperature.setText(response.body().getHeWeather6().get(0).getNow().getTmp());//温度

if (flag) {

ivLocation.setVisibility(View.VISIBLE);//显示定位图标

} else {

ivLocation.setVisibility(View.GONE);//显示定位图标

}

tvCity.setText(response.body().getHeWeather6().get(0).getBasic().getLocation());//城市

tvInfo.setText(response.body().getHeWeather6().get(0).getNow().getCond_txt());//天气状况

//修改上次更新时间的结果显示 -> 更加人性化

String datetime = response.body().getHeWeather6().get(0).getUpdate().getLoc();//赋值

String time = datetime.substring(11);//截去前面的字符,保留后面所有的字符,就剩下 22:00

tvOldTime.setText(“上次更新时间:” + WeatherUtil.showTimeInfo(time) + time);

tvWindDirection.setText("风向 " + response.body().getHeWeather6().get(0).getNow().getWind_dir());//风向

tvWindPower.setText("风力 " + response.body().getHeWeather6().get(0).getNow().getWind_sc() + “级”);//风力

wwBig.startRotate();//大风车开始转动

wwSmall.startRotate();//小风车开始转动

/**

  • 查询7天天气预报

*/

//最低温和最高温

tvLowHeight.setText(response.body().getHeWeather6().get(0).getDaily_forecast().get(0).getTmp_min() + " / " +

response.body().getHeWeather6().get(0).getDaily_forecast().get(0).getTmp_max() + “℃”);

if (response.body().getHeWeather6().get(0).getDaily_forecast() != null) {

List<WeatherResponse.HeWeather6Bean.DailyForecastBean> data

= response.body().getHeWeather6().get(0).getDaily_forecast();

mListDailyForecast.clear();//添加数据之前先清除

mListDailyForecast.addAll(data);//添加数据

mAdapter.notifyDataSetChanged();//刷新列表

} else {

ToastUtils.showShortToast(context, “天气预报数据为空”);

}

/**

  • 查询逐小时天气数据

*/

if (response.body().getHeWeather6().get(0).getHourly() != null) {

List<WeatherResponse.HeWeather6Bean.HourlyBean> data

= response.body().getHeWeather6().get(0).getHourly();

mListHourlyBean.clear();//添加数据之前先清除

mListHourlyBean.addAll(data);//添加数据

mAdapterHourly.notifyDataSetChanged();//刷新列表

} else {

ToastUtils.showShortToast(context, “逐小时预报数据为空”);

}

/**

  • 生活指数

*/

List<WeatherResponse.HeWeather6Bean.LifestyleBean> data = response.body().getHeWeather6().get(0).getLifestyle();

if (!ObjectUtils.isEmpty(data)) {

for (int i = 0; i < data.size(); i++) {

switch (data.get(i).getType()){

case “uv”:

tvUv.setText(“紫外线:” + data.get(i).getTxt());

break;

case “comf”:

tvComf.setText(“舒适度:” + data.get(i).getTxt());

break;

case “drsg”:

tvDrsg.setText(“穿衣指数:” + data.get(i).getTxt());

break;

case “flu”:

tvFlu.setText(“感冒指数:” + data.get(i).getTxt());

break;

case “sport”:

tvSport.setText(“运动指数:” + data.get(i).getTxt());

break;

case “trav”:

tvTrav.setText(“旅游指数:” + data.get(i).getTxt());

break;

case “cw”:

tvCw.setText(“洗车指数:” + data.get(i).getTxt());

break;

case “air”:

tvAir.setText(“空气指数:” + data.get(i).getTxt());

break;

}

}

} else {

ToastUtils.showShortToast(context, “生活指数数据为空”);

}

}else {

ToastUtils.showShortToast(context,“天气数据为空”);

}

}else {

ToastUtils.showShortToast(context, CodeToStringUtils.WeatherCode(response.body().getHeWeather6().get(0).getStatus()));

}

改到这里就是初步改完了,运行一下:

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

很明显,和之前什么变化都没有,但是,里面的业务处理方式发生了改变,之前是一次性请求四次接口,现在是变成一个接口了,无疑在机制上有了优化,现在就可以注释掉其他的代码了。

打开ApiService

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

这里将之前的四个API注释掉。

再打开订阅器

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

然后再回到MainActivity

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

将这四个报错的返回方法注释掉,这是你的页面是不会有报错的,然后再运行一下,确保没有问题。好了,已经运行过没有问题了,那么最后就是删除掉注释的代码了。

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

这四个实体bean也可以删除了,删除之后再运行一下,OK,没有问题。也算是为应用做了一次瘦身了,下面就是优化一下用户的体验。

优化UI


增加逐小时天气预报详情和七天天气预报详情,

这个我打算用弹窗来做,首先是逐小时天气预报的详情,创建一个弹窗的背景样式

在项目的drawable下创建shape_white_5.xml文件

样式代码如下:

<?xml version="1.0" encoding="utf-8"?>

① 逐小时天气预报的详情UI

在项目的layout文件下创建window_hourly_detail.xml文件

布局代码如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:orientation=“vertical”

android:background=“@drawable/shape_white_5”

android:padding=“@dimen/dp_12”

android:layout_width=“300dp”

android:layout_height=“400dp”>

<TextView

android:gravity=“center_vertical”

android:textColor=“@color/black”

android:textSize=“@dimen/sp_16”

android:textStyle=“bold”

android:id=“@+id/tv_time”

android:layout_width=“match_parent”

android:layout_height=“@dimen/dp_40”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“温度”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_tem”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“天气状况”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_cond_txt”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“风向360角度”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_wind_deg”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“风向”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_wind_dir”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“风力”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_wind_sc”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“风速”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_wind_spd”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“相对湿度”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_hum”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“大气压强”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_pres”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“降水概率”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_pop”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“露点温度”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_dew”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“云量”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_cloud”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

由于这一次的弹窗是屏幕中间出现,所以增加动画效果和代码,在mvplibrary模块下的anim文件夹中增加出现和隐藏的动画xml文件

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

window_hidden_anim.xml

<?xml version="1.0" encoding="utf-8"?>

<scale

android:duration=“300”

android:fromXScale=“1.0”

android:fromYScale=“1.0”

android:pivotX=“50%”

android:pivotY=“50%”

android:toXScale=“0.5”

android:toYScale=“0.5” />

<alpha

android:duration=“300”

android:fromAlpha=“1.0”

android:interpolator=“@android:anim/accelerate_interpolator”

android:toAlpha=“0.0” />

window_show_anim.xml

<?xml version="1.0" encoding="utf-8"?>

<scale

android:duration=“300”

android:fromXScale=“0.6”

android:fromYScale=“0.6”

android:pivotX=“50%”

android:pivotY=“50%”

android:toXScale=“1.0”

android:toYScale=“1.0” />

<alpha

android:duration=“300”

android:fromAlpha=“0.0”

android:interpolator=“@android:anim/decelerate_interpolator”

android:toAlpha=“1.0” />

然后在styles.xml文件中添加

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

这里还会用到一个测量的工具类SizeUtils.java

代码如下:

package com.llw.mvplibrary.utils;

import android.content.Context;

import android.util.DisplayMetrics;

import android.util.TypedValue;

import android.view.View;

import android.view.ViewGroup;

/**

  • dp sp px 转换 view 测量工个类

*/

public final class SizeUtils {

private SizeUtils() {

throw new UnsupportedOperationException(“u can’t instantiate me…”);

}

/**

  • Value of dp to value of px.

  • @param dpValue The value of dp.

  • @return value of px

*/

public static int dp2px(Context context, final float dpValue) {

final float scale = context.getApplicationContext().getResources().getDisplayMetrics().density;

return (int) (dpValue * scale + 0.5f);

}

/**

  • Value of px to value of dp.

  • @param pxValue The value of px.

  • @return value of dp

*/

public static int px2dp(Context context, final float pxValue) {

final float scale = context.getApplicationContext().getResources().getDisplayMetrics().density;

return (int) (pxValue / scale + 0.5f);

}

/**

  • Value of sp to value of px.

  • @param spValue The value of sp.

  • @return value of px

*/

public static int sp2px(Context context, final float spValue) {

final float fontScale = context.getApplicationContext().getResources().getDisplayMetrics().scaledDensity;

return (int) (spValue * fontScale + 0.5f);

}

/**

  • Value of px to value of sp.

  • @param pxValue The value of px.

  • @return value of sp

*/

public static int px2sp(Context context, final float pxValue) {

final float fontScale = context.getApplicationContext().getResources().getDisplayMetrics().scaledDensity;

return (int) (pxValue / fontScale + 0.5f);

}

/**

  • Converts an unpacked complex data value holding a dimension to its final floating

  • point value. The two parameters unit and value

  • are as in {@link TypedValue#TYPE_DIMENSION}.

  • @param value The value to apply the unit to.

  • @param unit The unit to convert from.

  • @return The complex floating point value multiplied by the appropriate

  • metrics depending on its unit.

*/

public static float applyDimension(Context context, final float value, final int unit) {

DisplayMetrics metrics = context.getApplicationContext().getResources().getDisplayMetrics();

switch (unit) {

case TypedValue.COMPLEX_UNIT_PX:

return value;

case TypedValue.COMPLEX_UNIT_DIP:

return value * metrics.density;

case TypedValue.COMPLEX_UNIT_SP:

return value * metrics.scaledDensity;

case TypedValue.COMPLEX_UNIT_PT:

return value * metrics.xdpi * (1.0f / 72);

case TypedValue.COMPLEX_UNIT_IN:

return value * metrics.xdpi;

case TypedValue.COMPLEX_UNIT_MM:

return value * metrics.xdpi * (1.0f / 25.4f);

}

return 0;

}

/**

  • Force get the size of view.

  • e.g.

  • 
    
  • SizeUtils.forceGetViewSize(view, new SizeUtils.onGetSizeListener() {

  • Override
    
  • public void onGetSize(final View view) {
    
  •     view.getWidth();
    
  • }
    
  • });

  • @param view The view.

  • @param listener The get size listener.

*/

public static void forceGetViewSize(final View view, final onGetSizeListener listener) {

view.post(new Runnable() {

@Override

public void run() {

if (listener != null) {

listener.onGetSize(view);

}

}

});

}

/**

  • Return the width of view.

  • @param view The view.

  • @return the width of view

*/

public static int getMeasuredWidth(final View view) {

return measureView(view)[0];

}

/**

  • Return the height of view.

  • @param view The view.

  • @return the height of view

*/

public static int getMeasuredHeight(final View view) {

return measureView(view)[1];

}

/**

  • Measure the view.

  • @param view The view.

  • @return arr[0]: view’s width, arr[1]: view’s height

*/

public static int[] measureView(final View view) {

ViewGroup.LayoutParams lp = view.getLayoutParams();

if (lp == null) {

lp = new ViewGroup.LayoutParams(

ViewGroup.LayoutParams.MATCH_PARENT,

ViewGroup.LayoutParams.WRAP_CONTENT

);

}

int widthSpec = ViewGroup.getChildMeasureSpec(0, 0, lp.width);

int lpHeight = lp.height;

int heightSpec;

if (lpHeight > 0) {

heightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY);

} else {

heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

}

view.measure(widthSpec, heightSpec);

return new int[]{view.getMeasuredWidth(), view.getMeasuredHeight()};

}

///

// interface

///

public interface onGetSizeListener {

void onGetSize(View view);

}

}

现在去LiWindow.java中增加中间显示的代码.

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

增加的代码我也贴一下:

/**

  • 中间显示

  • @param mView

*/

public void showCenterPopupWindow(View mView,int width,int height) {

mPopupWindow = new PopupWindow(mView,

width, height, true);

mPopupWindow.setContentView(mView);

mPopupWindow.setAnimationStyle(R.style.AnimationCenterFade); //设置动画

mPopupWindow.showAtLocation(mView, Gravity.CENTER, 0, 0);

mPopupWindow.update();

setBackgroundAlpha(0.5f,mContext);

WindowManager.LayoutParams nomal = ((Activity) mContext).getWindow().getAttributes();

nomal.alpha = 0.5f;

((Activity) mContext).getWindow().setAttributes(nomal);

mPopupWindow.setOnDismissListener(closeDismiss);

}

现在修改item_weather_hourly_list.xml,增加了一个id和点击的水波纹效果,代码如下,复制粘贴即可:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:orientation=“vertical”

android:gravity=“center_horizontal”

android:id=“@+id/item_hourly”

android:foreground=“@drawable/bg_white”

android:padding=“8dp”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”>

<TextView

android:id=“@+id/tv_time”

android:textColor=“#FFF”

android:text=“上午10:00”

android:textSize=“14sp”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”/>

<ImageView

android:layout_marginTop=“12dp”

android:layout_marginBottom=“8dp”

android:id=“@+id/iv_weather_state”

android:background=“@mipmap/icon_100”

android:layout_width=“30dp”

android:layout_height=“30dp”/>

<TextView

android:textSize=“20sp”

android:id=“@+id/tv_temperature”

android:textColor=“#FFF”

android:text=“25℃”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”/>

再修改WeatherHourlyAdapter.java适配器

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

添加点击事件的id。

进入MainActivity.java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

这个代码就手写一下吧,也不多,然后是这个弹窗的方法

//显示逐三小时详情天气信息弹窗

private void showHourlyWindow(WeatherResponse.HeWeather6Bean.HourlyBean data) {

liWindow = new LiWindow(context);

final View view = LayoutInflater.from(context).inflate(R.layout.window_hourly_detail, null);

TextView tv_time = view.findViewById(R.id.tv_time);//时间

TextView tv_tem = view.findViewById(R.id.tv_tem);//温度

TextView tv_cond_txt = view.findViewById(R.id.tv_cond_txt);//天气状态描述

TextView tv_wind_deg = view.findViewById(R.id.tv_wind_deg);//风向360角度

TextView tv_wind_dir = view.findViewById(R.id.tv_wind_dir);//风向

TextView tv_wind_sc = view.findViewById(R.id.tv_wind_sc);//风力

TextView tv_wind_spd = view.findViewById(R.id.tv_wind_spd);//风速

TextView tv_hum = view.findViewById(R.id.tv_hum);//相对湿度

TextView tv_pres = view.findViewById(R.id.tv_pres);//大气压强

TextView tv_pop = view.findViewById(R.id.tv_pop);//降水概率

TextView tv_dew = view.findViewById(R.id.tv_dew);//露点温度

TextView tv_cloud = view.findViewById(R.id.tv_cloud);//云量

String datetime = data.getTime();//赋值

String time = datetime.substring(11);//截去前面的字符,保留后面所有的字符,就剩下 22:00

tv_time.setText(WeatherUtil.showTimeInfo(time) + time);

tv_tem.setText(data.getTmp() + “℃”);

tv_cond_txt.setText(data.getCond_txt());

tv_wind_deg.setText(data.getWind_deg()+“°”);

tv_wind_dir.setText(data.getWind_dir());

tv_wind_sc.setText(data.getWind_sc()+“级”);

tv_wind_spd.setText(data.getWind_spd() + “公里/小时”);

tv_hum.setText(data.getHum());

tv_pres.setText(data.getPres());

tv_pop.setText(data.getPop() + “%”);

tv_dew.setText(data.getDew()+“℃”);

tv_cloud.setText(data.getCloud());

liWindow.showCenterPopupWindow(view, SizeUtils.dp2px(context, 300),SizeUtils.dp2px(context, 400));

}

OK,到目前为止,可以运行一下了

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

OK,还是蛮简单的吧(PS:由于没有UI,大家这个都知道开发的审美,就先将就一下,如果有好的建议可以给我提)。

② 未来七天天气的详情UI

其实这个和逐小时的比较类似,不过要比逐小时的数据要多一些,

在项目的layout文件下创建window_forecast_detail.xml文件

布局代码如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:orientation=“vertical”

android:background=“@drawable/shape_white_5”

android:padding=“@dimen/dp_12”

android:layout_width=“300dp”

android:layout_height=“500dp”>

<TextView

android:gravity=“center_vertical”

android:textColor=“@color/black”

android:textSize=“@dimen/sp_16”

android:textStyle=“bold”

android:id=“@+id/tv_datetime”

android:layout_width=“match_parent”

android:layout_height=“@dimen/dp_40”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“最高温”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_tmp_max”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“最低温”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_tmp_min”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“紫外线强度”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_uv_index”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“白天天气状况”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_cond_txt_d”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“晚上天气状况”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_cond_txt_n”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“风向360角度”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_wind_deg”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“风向”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_wind_dir”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“风力”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_wind_sc”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“风速”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_wind_spd”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“相对湿度”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_hum”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“大气压强”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_pres”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“降水量”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_pcpn”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“降水概率”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_pop”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<LinearLayout

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”>

<TextView

android:text=“能见度”

android:textColor=“@color/black”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:textColor=“@color/black”

android:id=“@+id/tv_vis”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

修改item_weather_forecast_list.xml增加ID和点击效果

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

修改WeatherForecastAdapter.java,绑定点击事件的id

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

这里先添加一个事件日期的工具类进去,是我好久之前写的,不过也能用的上DateUtils.java,代码如下:

package com.llw.goodweather.utils;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.GregorianCalendar;

import java.util.Locale;

public class DateUtils {

//获取当前完整的日期和时间

public static String getNowDateTime() {

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

return sdf.format(new Date());

}

//获取当前日期

public static String getNowDate() {

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);

return sdf.format(new Date());

}

//前一天

public static String getYesterday(Date date) {

String tomorrow = “”;

Calendar calendar = new GregorianCalendar();

calendar.setTime(date);

calendar.add(calendar.DATE, -1);

date = calendar.getTime();

SimpleDateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd”);

tomorrow = formatter.format(date);

return tomorrow;

}

//后一天

public static String getTomorrow(Date date) {

String tomorrow = “”;

Calendar calendar = new GregorianCalendar();

calendar.setTime(date);

calendar.add(calendar.DATE, +1);

date = calendar.getTime();

SimpleDateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd”);

tomorrow = formatter.format(date);

return tomorrow;

}

//获取当前时间

public static String getNowTime() {

SimpleDateFormat sdf = new SimpleDateFormat(“HH:mm:ss”);

return sdf.format(new Date());

}

//获取当前日期(精确到毫秒)

public static String getNowTimeDetail() {

SimpleDateFormat sdf = new SimpleDateFormat(“HH:mm:ss.SSS”);

return sdf.format(new Date());

}

//获取今天是星期几

public static String getWeekOfDate(Date date) {

String[] weekDays = {“星期日”, “星期一”, “星期二”, “星期三”, “星期四”, “星期五”, “星期六”};

Calendar cal = Calendar.getInstance();

cal.setTime(date);

int w = cal.get(Calendar.DAY_OF_WEEK) - 1;

if (w < 0)

w = 0;

return weekDays[w];

}

//计算星期几

private static int getDayOfWeek(String dateTime) {

Calendar cal = Calendar.getInstance();

if (dateTime.equals(“”)) {

cal.setTime(new Date(System.currentTimeMillis()));

} else {

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”, Locale.getDefault());

Date date;

try {

date = sdf.parse(dateTime);

} catch (ParseException e) {

date = null;

e.printStackTrace();

}

if (date != null) {

cal.setTime(new Date(date.getTime()));

}

}

return cal.get(Calendar.DAY_OF_WEEK);

}

//根据年月日计算是星期几并与当前日期判断 非昨天、今天、明天 则以星期显示

public static String Week(String dateTime) {

String week = “”;

String yesterday = “”;

String today = “”;

String tomorrow = “”;

yesterday = getYesterday(new Date());

today = getNowDate();

tomorrow = getTomorrow(new Date());

if (dateTime.equals(yesterday)) {

week = “昨天”;

} else if (dateTime.equals(today)) {

week = “今天”;

} else if (dateTime.equals(tomorrow)) {

week = “明天”;

} else {

switch (getDayOfWeek(dateTime)) {

case 1:

week = “星期日”;

break;

case 2:

week = “星期一”;

break;

case 3:

week = “星期二”;

break;

case 4:

week = “星期三”;

break;

case 5:

week = “星期四”;

break;

case 6:

week = “星期五”;

break;

case 7:

week = “星期六”;

break;

}

}

return week;

}

//将时间戳转化为对应的时间(10位或者13位都可以)

public static String formatTime(long time) {

String times = null;

if (String.valueOf(time).length() > 10) {// 10位的秒级别的时间戳

times = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).format(new Date(time * 1000));

} else {// 13位的秒级别的时间戳

times = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).format(time);

}

return times;

}

//将时间字符串转为时间戳字符串

public static String getStringTimestamp(String time) {

String timestamp = null;

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

最后

这里我希望可以帮助到大家提升进阶。

内容包含:Android学习PDF+架构视频+面试文档+源码笔记高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 这几块的内容。非常适合近期有面试和想在技术道路上继续精进的朋友。

喜欢本文的话,不妨给我点个小赞、评论区留言或者转发支持一下呗~

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!文章来源地址https://www.toymoban.com/news/detail-857815.html

  • 1;

if (w < 0)

w = 0;

return weekDays[w];

}

//计算星期几

private static int getDayOfWeek(String dateTime) {

Calendar cal = Calendar.getInstance();

if (dateTime.equals(“”)) {

cal.setTime(new Date(System.currentTimeMillis()));

} else {

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”, Locale.getDefault());

Date date;

try {

date = sdf.parse(dateTime);

} catch (ParseException e) {

date = null;

e.printStackTrace();

}

if (date != null) {

cal.setTime(new Date(date.getTime()));

}

}

return cal.get(Calendar.DAY_OF_WEEK);

}

//根据年月日计算是星期几并与当前日期判断 非昨天、今天、明天 则以星期显示

public static String Week(String dateTime) {

String week = “”;

String yesterday = “”;

String today = “”;

String tomorrow = “”;

yesterday = getYesterday(new Date());

today = getNowDate();

tomorrow = getTomorrow(new Date());

if (dateTime.equals(yesterday)) {

week = “昨天”;

} else if (dateTime.equals(today)) {

week = “今天”;

} else if (dateTime.equals(tomorrow)) {

week = “明天”;

} else {

switch (getDayOfWeek(dateTime)) {

case 1:

week = “星期日”;

break;

case 2:

week = “星期一”;

break;

case 3:

week = “星期二”;

break;

case 4:

week = “星期三”;

break;

case 5:

week = “星期四”;

break;

case 6:

week = “星期五”;

break;

case 7:

week = “星期六”;

break;

}

}

return week;

}

//将时间戳转化为对应的时间(10位或者13位都可以)

public static String formatTime(long time) {

String times = null;

if (String.valueOf(time).length() > 10) {// 10位的秒级别的时间戳

times = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).format(new Date(time * 1000));

} else {// 13位的秒级别的时间戳

times = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).format(time);

}

return times;

}

//将时间字符串转为时间戳字符串

public static String getStringTimestamp(String time) {

String timestamp = null;

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

[外链图片转存中…(img-pR9J0zJ8-1713113885069)]

[外链图片转存中…(img-CDByZMwm-1713113885070)]

[外链图片转存中…(img-gM4b6UTd-1713113885070)]

[外链图片转存中…(img-IIXvtiRq-1713113885070)]

[外链图片转存中…(img-uVTZEn1W-1713113885071)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

最后

这里我希望可以帮助到大家提升进阶。

内容包含:Android学习PDF+架构视频+面试文档+源码笔记高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 这几块的内容。非常适合近期有面试和想在技术道路上继续精进的朋友。

喜欢本文的话,不妨给我点个小赞、评论区留言或者转发支持一下呗~

Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示,程序员,android,ui,java

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

到了这里,关于Android 天气APP(十四)修复UI显示异常、优化业务代码逻辑、增加详情天气显示的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Android应用优化之最基本的UI层显示优化

    .Android Studio有自带的视图分析工具 Layout Inspector(布局检查器),打开方式菜单栏Tools– Layout Inspector。 可以看到Layout Inspector最右侧的属性栏可以查看每一个View的所附带的属性及属性值。 3.接下来我们主要分析以下三个问题: 【问题1】没有用的父布局 通过工具和查看代码,

    2024年04月28日
    浏览(28)
  • Android Ble蓝牙App(四)UI优化和描述符

      上一篇中了解了特性和属性,同时显示设备蓝牙服务下的特性和属性,本文中就需要来使用这些特性和属性来完成一些功能。 Ble蓝牙App(一)扫描 Ble蓝牙App(二)连接与发现服务 Ble蓝牙App(三)特性和属性 Ble蓝牙App(四)UI优化和描述符 Ble蓝牙App(五)数据操作   

    2024年02月13日
    浏览(30)
  • Android Compose 新闻App(三)网络数据Compose UI显示加载、Room和DataStore使用

    正文 =============================================================== 后面的内容涉及到样式布局组件,内容比较多。 一、样式 在这里我们先进行样式的配置,打开ui.theme文件夹。 首先是修改Color.kt文件 val Blue200 = Color(0xFF979FF2) val Blue300 = Color(0xFF6D7DEA) val Blue700 = Color(0xFF0068C2) val Blue800 = Col

    2024年04月09日
    浏览(61)
  • Android——一个简单的天气APP

    EasyWeather演示效果视频 此天气数据源采用心知天气API(试用版),免费版获取数据有限,只能获取普通的温度、湿度等,例如压力、云量、可见度等均获取不到,试用版相当于正式版,可以获取大部分数据,试用日期是14天。 首页不同城市天气页面之间的滑动采用的是 ViewPager

    2023年04月26日
    浏览(33)
  • Android实现-心知天气API接口开发(天气预报app)

    自己开发app之心知天气APP程序代码粘贴即可用。完整代码附最后。 第一步:去知心天气注册开发者账号查看自己的token。注册好登录进去--控制台---免费版--秘钥。这里的秘钥就是自己的token。(有兴趣的可以看开发文档,这里就不多介绍了)  第二步,下载素材包。点击文档

    2024年02月03日
    浏览(99)
  • 基于Android实现的天气预测APP

    网络数据源使用 Retrofit 库访问彩云 API 提供的 Webservice 接口来实现。 Retrofit 通过封装络请求和数据解析,极地提升了开发效率。并且持定义数据解析在封装所有网络请求的 API 时,我使用了协程技术来简化 Retrofit 回调的写法。 1.1.1 数据存储 本地数据源使用 SharedPreferences 持久

    2024年02月01日
    浏览(39)
  • 卸载WPS后如何修复Office文档图标显示异常

    卸载WPS后发现Office文件word、ppt、excel的图标变成空白图标,该如何解决? 尝试了很多方法后,终于筛选出两种简单且有效的方法。 (有文章说可以修改注册表,但我建议慎用,如果一不小心修改注册表错误,后果可能会很麻烦) 方法一: 解铃还需系铃人,可以使用Office自带

    2024年02月04日
    浏览(52)
  • kotlin 编写一个简单的天气预报app(六)使用recyclerView显示forecast内容

    要使用RecyclerView显示天气预报的内容 先在grandle里添加recyclerView的引用 创建一个RecyclerView控件:在布局文件中,添加一个RecyclerView控件,用于显示天气预报的列表。 这是一个包含三个TextView的LinearLayout布局,用于显示天气相关的数据。每个TextView都有一个唯一的id,可用于在代

    2024年02月13日
    浏览(70)
  • Android Studio 实现天气预报App (简单方便展示内容超多)

    🍅 文章末尾有获取完整项目源码方式 🍅 目录 前言 一、任务介绍 1.1 背景 1.2目的和意义 二、 实现介绍 视频演示 2.1 启动页实现 2.2注册页面实现 2.3 登陆页面实现 2.4 首页实现 2.5 城市管理列表页面实现                三、获取源码         在使用Android Studio开发

    2024年04月24日
    浏览(37)
  • 安卓大作业:使用Android Studio开发天气预报APP(使用sqlite数据库)

    今天我来分享一下如何使用Android Studio开发一个天气预报APP。在文中,我们将使用第三方接口获取实时天气数据,并显示在APP界面上。 首先,打开Android Studio并创建一个新的项目。在创建新项目时,我们需要设置项目名称、包名和支持的最低API级别。 为了获取实时天气数据,

    2024年02月08日
    浏览(46)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包