本市天气(百度定位与车联网之天气查询)(二)

简介: 本市天气(百度定位与车联网之天气查询)(二)

2.定位到本市(也就是本地)


①添加密钥


在配置文件AndroidManifest.xml中application标签中添加如下代码:


<meta-data
    android:name="com.baidu.lbsapi.API_KEY"
    android:value="qxpnHHLKBgCrTEUNPAwDF7Df" />       //key:开发者申请的key


②在application标签中声明service组件,每个app拥有自己单独的定位service

<service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote">
    <intent-filter>
    <action android:name="com.baidu.location.service_v2.2"> </action>
</intent-filter>
</service>


③申明使用权限

<!-- 这个权限用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<!-- 这个权限用于访问GPS定位-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<!-- 获取运营商信息,用于支持提供运营商信息相关的接口-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<!-- 用于读取手机当前的状态-->
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<!-- 访问网络,网络定位需要上网-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- SD卡读取权限,用户写入离线定位数据-->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>


④合理使用定位及天气

我们知道,怎么获取天气,不造成应用程序的卡盾,又可以在用户神不知鬼不觉的时候更新天气呢?


答案是定时更新定位天气信息。


那么广播和Service就可以达到你想要的效果。


我们在Service里面定时定位和更新天气并存储到SharedPreferences文件中。我们在这里设置每8个小时更新一次天气。


我们在启动一个Service执行定位功能。


WeatherService代码如下:


首先定义两个成员变量:


private LocationClient mLocationClient = null;
private BDLocationListener myListener = new MyLocationListener();


当启动Service后会首先执行onCreate(),我们在里面初始化成员变量:


@Override
public void onCreate() {
    super.onCreate();
    mLocationClient = new LocationClient(getApplicationContext());     //声明LocationClient类
    mLocationClient.registerLocationListener(myListener);    //注册监听函数
    initLocation();
}


这里设置了定位的监听函数,当请求定位的时候,在监听函数onReceiveLocation中返回定位的结果信息。


监听函数的代码如下:


public class MyLocationListener implements BDLocationListener {
    @Override
    public void onReceiveLocation(BDLocation location) {
        //Receive Location
        StringBuffer sb = new StringBuffer(256);
        sb.append("time : ");
        sb.append(location.getTime());
        sb.append("\nerror code : ");
        sb.append(location.getLocType());
        sb.append("\nlatitude : ");
        sb.append(location.getLatitude());
        sb.append("\nlontitude : ");
        sb.append(location.getLongitude());
        sb.append("\nradius : ");
        sb.append(location.getRadius());
        if (location.getLocType() == BDLocation.TypeGpsLocation) {// GPS定位结果
            sb.append("\nspeed : ");
            sb.append(location.getSpeed());// 单位:公里每小时
            sb.append("\nsatellite : ");
            sb.append(location.getSatelliteNumber());
            sb.append("\nheight : ");
            sb.append(location.getAltitude());// 单位:米
            sb.append("\ndirection : ");
            sb.append(location.getDirection());// 单位度
            sb.append("\naddr : ");
            sb.append(location.getAddrStr());
            sb.append("\ndescribe : ");
            sb.append("gps定位成功");
        } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {// 网络定位结果
            sb.append("\naddr : ");
            sb.append(location.getAddrStr());
            //运营商信息
            sb.append("\noperationers : ");
            sb.append(location.getOperators());
            sb.append("\ndescribe : ");
            sb.append("网络定位成功");
        } else if (location.getLocType() == BDLocation.TypeOffLineLocation) {// 离线定位结果
            sb.append("\ndescribe : ");
            sb.append("离线定位成功,离线定位结果也是有效的");
        } else if (location.getLocType() == BDLocation.TypeServerError) {
            sb.append("\ndescribe : ");
            sb.append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因");
        } else if (location.getLocType() == BDLocation.TypeNetWorkException) {
            sb.append("\ndescribe : ");
            sb.append("网络不同导致定位失败,请检查网络是否通畅");
        } else if (location.getLocType() == BDLocation.TypeCriteriaException) {
            sb.append("\ndescribe : ");
            sb.append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
        }
        sb.append("\nlocationdescribe : ");
        sb.append(location.getLocationDescribe());// 位置语义化信息
        Log.i("liyuanjinglyj",sb.toString());
        //Log.i("liyuanjinglyj", location.getCity());
        //Log.i("liyuanjinglyj",location.getCity().substring(0,location.getCity().length()-1));
        mLocationClient.stop();
    }
}


在后面使用location.getCity()返回你所定位的市级信息,比如你是宜昌市的就返回的是宜昌市。


start:启动定位SDK。 stop:关闭定位SDK。调用start之后只需要等待定位结果自动回调即可。

开发者定位场景如果是单次定位的场景,在收到定位结果之后直接调用stop函数即可。

如果stop之后仍然想进行定位,可以再次start等待定位结果回调即可。


我们基本8个小时才执行一次,所以记得用完后关闭定位SDK。节省系统资源。


initLocation为初始化定位所需要的参数,代码如下:


private void initLocation(){
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy
    );//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系
    int span=1000;
    option.setScanSpan(span);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
    option.setOpenGps(true);//可选,默认false,设置是否使用gps
    option.setLocationNotify(true);//可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
    option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIgnoreKillProcess(false);//可选,默认false,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认杀死
    option.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集
    option.setEnableSimulateGps(false);//可选,默认false,设置是否需要过滤gps仿真结果,默认需要
    mLocationClient.setLocOption(option);
}


根据你的需要可以适当的更改数据,或删除数据。


为了达到我们的定时功能,我们需要每隔8个小时启动广播,而且当执行完onCreate()函数后,接着Service会执行onStartCommand方法。代码如下:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    updateWeather();
    AlarmManager manager=(AlarmManager)getSystemService(ALARM_SERVICE);
    int anHour=8*60*60*1000;
    long triggerAtTime= SystemClock.elapsedRealtime()+anHour;
    Intent i=new Intent(this, AutoUpdateReceiver.class);
    PendingIntent pi=PendingIntent.getBroadcast(this,0,i,0);
    manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,triggerAtTime,pi);
    return super.onStartCommand(intent,flags,startId);
}
/**
 * 开始定位
 */
private void updateWeather(){
    mLocationClient.start();
}


PendingIntent就是延迟的Intent这个不必多做解释了,相信大家都懂,我们这里使用AlarmManager实现定时功能。


SystemClock.elapsedRealtime():从开机到现在的毫秒数。


AlarmManager.set方法参数:

set(int type,long startTime,PendingIntent pi);

该方法用于设置一次性闹钟,第一个参数表示闹钟类型,第二个参数表示闹钟执行时间,第三个参数表示闹钟响应动作。


type:AlarmManager.ELAPSED_REALTIME_WAKEUP表示闹钟在睡眠状态下会唤醒系统并执行提示功能,该状态下闹钟也使用相对时间,状态值为2;


startTime: 闹钟的第一次执行时间。也就是8个小时之后。


pi:绑定了闹钟的执行动作,比如发送一个广播、给出提示等等


我们在MainActivity.class的onCreate()方法中启动了该服务:

Intent i=new Intent(this,WeatherService.class);
startService(i);


那么八个小时之后,我们会在广播AutoUpdateReceiver.class中再次启动服务:


public class AutoUpdateReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent i=new Intent(context, WeatherService.class);
        context.startService(i);
    }
}


这样WeatherService就会一直在后台运行,并保证每8个小时更新一次天气。


⑤配置广播与服务


最后在AndroidManifest.xml中配置广播与服务:


<service android:name="com.example.liyuanjing.service.WeatherService"/>
<receiver android:name="com.example.liyuanjing.receiver.AutoUpdateReceiver"/>


3.获取天气信息


其实百度不仅提供了定位的功能,也提供了天气的功能,刚才在本文第一节的创建应用中的启动服务中,增加一个功能,天气就在这个功能中,叫车联网API。把勾勾加上。我们就可以使用百度提供的天气服务了。


那么怎么获取天气呢?


只需要请求该URL就可以获取天气的JSON数据了,下面是URL格式:

" http://api.map.baidu.com/telematics/v3/weather?location ="+ URLEncoder.encode(location.getCity().substring(0, location.getCity().length() - 1),

"UTF-8")+"&output=json&ak=" +"你创建应用时候获取的AK"+"&mcode="+"你创建应用的时候输入的安全码";


如上所示,location.getCity()就是刚才定位里面的市级信息。中间转换成UTF-8编码,而且截取了字符串,比如你获取的市级信息为宜昌市,那么我们网址要的只是宜昌两个字的编码,必须把市删掉,所以截取了字符串,把市去掉了。


下面我们开始完善我们的WeatherService.class,让它不仅可以定位,而且可以获取天气信息。


在上个步骤定位回调函数MyLocationListener.onReceiveLocation的末尾加入如下代码:

try {
    String url="http://api.map.baidu.com/telematics/v3/weather?location="+ URLEncoder.encode(location.getCity().substring(0, location.getCity().length() - 1), "UTF-8")+"&output=json&ak=" +
            "qxpnHHLKBgCrTEUNPAwDF7Df"+"&mcode="+"9E:8B:66:E6:5E:73:FD:3A:AE:56:E4:22:68:DE:8E:6C:FC:16:E0:22;com.example.liyuanjing.demowy";
    new CoolAsyncTask().execute(url);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}


并在WeatherService.class中创建CoolAsyncTask的异步加载类,如下:

private class CoolAsyncTask extends AsyncTask<String,Integer,String> {
    @Override
    protected String doInBackground(String... params) {
        String str=null;
        try {
            str=new String(ConnectNetwork.getImageDat(params[0]));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }
    @Override
    protected void onPostExecute(String s) {
        WeatherItem item =WeatherJson.readWeatherFromInputStream(s);
        SharedPreferences.Editor editor= PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
        editor.putString("pm",item.getPm());
        editor.putString("current_city", item.getCurrentCity());
        editor.putString("current_date",item.getDate());
        editor.putString("weather",item.getWeather());
        editor.putString("wind",item.getWind());
        editor.putString("temperature",item.getTemperature());
        editor.commit();
    }
}


这样我们请求天气信息,并用Json解析后存入SharedPreferences文件中。


这样,我们的天气请求Service就完成了。


4.Json解析百度天气


在上一个步骤中,有一个Json解析类不曾讲解到,就是WeatherJson。下面我们来看看它的代码:

public class WeatherJson {
    public static WeatherItem readWeatherFromInputStream(String str){
        WeatherItem weatherItem=null;
        try {
            weatherItem=new WeatherItem();
            //遍历第一层数据
            JSONObject rootJson = new JSONObject(str);
            JSONArray jsonArray=rootJson.getJSONArray("results");
            //遍历第二层数据
            JSONObject resultsJsonObject= (JSONObject) jsonArray.get(0);
            //Log.i("liyuanjinglyj",resultsJsonObject.getString("pm25"));
            //Log.i("liyuanjinglyj",resultsJsonObject.getString("currentCity"));
            weatherItem.setPm(resultsJsonObject.getString("pm25"));
            weatherItem.setCurrentCity(resultsJsonObject.getString("currentCity"));
            JSONArray weatherDataJsonArray=resultsJsonObject.getJSONArray("weather_data");
            //遍历第三层数据
            JSONObject nowJsonObject= (JSONObject) weatherDataJsonArray.get(0);
            //Log.i("liyuanjinglyj",nowJsonObject.getString("wind"));
            //Log.i("liyuanjinglyj",nowJsonObject.getString("weather"));
            //Log.i("liyuanjinglyj",nowJsonObject.getString("date"));
            //Log.i("liyuanjinglyj",nowJsonObject.getString("temperature"));
            weatherItem.setWind(nowJsonObject.getString("wind"));
            weatherItem.setWeather(nowJsonObject.getString("weather"));
            weatherItem.setDate(nowJsonObject.getString("date"));
            weatherItem.setTemperature(nowJsonObject.getString("temperature"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return weatherItem;
    }
}


下面我们来看看从百度返回的Json格式,如下:

{
error: 0,
status: "success",
date: "2013-07-17",
results:
[
{
currentCity: "北京市",
pm25: "166",
index: [
{
title: "穿衣",
zs: "舒适",
tipt: "穿衣指数",
des: "建议着长袖T恤、衬衫加单裤等服装。年老体弱者宜着针织长袖衬衫、马甲和长裤。"
},
{
title: "洗车",
zs: "不宜",
tipt: "洗车指数",
des: "不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。"
},
{
title: "感冒",
zs: "较易发",
tipt: "感冒指数",
des: "相对今天出现了较大幅度降温,较易发生感冒,体质较弱的朋友请注意适当防护。"
},
{
title: "运动",
zs: "较不宜",
tipt: "运动指数",
des: "有降水,推荐您在室内进行健身休闲运动;若坚持户外运动,须注意携带雨具并注意避雨防滑。"
},
{
title: "紫外线强度",
zs: "弱",
tipt: "紫外线强度指数",
des: "紫外线强度较弱,建议出门前涂擦SPF在12-15之间、PA+的防晒护肤品。"
}
],
weather_data:
[
{
date: "周三(今天, 实时:24℃)",
dayPictureUrl: " http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: " http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多云",
wind: "微风",
temperature: "23℃~ 15℃"
},
{
date: "明天(周四)",
dayPictureUrl: " http://api.map.baidu.com/images/weather/day/leizhenyu.png",
nightPictureUrl: " http://api.map.baidu.com/images/weather/night/zhongyu.png",
weather: "雷阵雨转中雨",
wind: "微风",
temperature: "29~22℃"
},
{
date: "后天(周五)",
dayPictureUrl: " http://api.map.baidu.com/images/weather/day/yin.png",
nightPictureUrl: " http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "阴转多云",
wind: "微风",
temperature: "31~23℃"
},
{
date: "大后天(周六)",
dayPictureUrl: " http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: " http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多云",
wind: "微风",
temperature: "31~24℃"
}
]
},
{
currentCity: "合肥市",
weather_data:
[
{
date: "今天(周三)",
dayPictureUrl: " http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: " http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多云",
wind: "东风3-4级",
temperature: "27℃"
},
{
date: "明天(周四)",
dayPictureUrl: " http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: " http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多云",
wind: "东北风3-4级",
temperature: "35~27℃"
},
{
date: "后天(周五)",
dayPictureUrl: " http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: " http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多云",
wind: "南风",
temperature: "35~27℃"
},
{
date: "大后天(周六)",
dayPictureUrl: " http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: " http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多云",
wind: "东风",
temperature: "34~27℃"
}
]
}
]
}

我们可以看到,我们所需要的Json数据大体上看仅有一个JsonObject。


所以我们获取的时候,首先直接用的JsonObject而不是JsonArray。但是我们要的数据都在results中。


我们不仅要获取results中的pm与currentCity。而且还要获取results中weather_data信息。前面属于第二层数据,weather_data中又是一个JsonArray。而我们要的只是今天的数据所以得到weather_data的第一个数据就可以了。


这样看起来上面的数据就简单多了把。


5.天气布局文件


下面就是布局文件weather_layout的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/weather_layout_main"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/lyj_title_bar_layout_main"
    android:layout_marginTop="-6dp"
    android:visibility="gone">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00000000">
        <ImageView
            android:layout_width="12dp"
            android:layout_height="6dp"
            android:layout_alignParentRight="true"
            android:layout_marginRight="18dp"
            android:background="@drawable/biz_main_more_menu_indication"/>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="40dp"
        android:background="#88ffffff">
        <LinearLayout
            android:id="@+id/dushu"
            android:layout_width="match_parent"
            android:layout_height="83dp"
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/weather_layout_current_one_image"
                android:layout_width="50dp"
                android:layout_height="83dp"
                android:background="@drawable/biz_more_menu_t2"/>
            <ImageView
                android:id="@+id/weather_layout_current_two_image"
                android:layout_width="50dp"
                android:layout_height="83dp"
                android:background="@drawable/biz_more_menu_t1"/>
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="83dp">
                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="24dp"
                    android:background="@drawable/biz_more_menu_weather_symbol"/>
                <TextView
                    android:id="@+id/weather_layout_temperature"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:text="@string/weather_layout_section"
                    android:textSize="18sp"/>
            </RelativeLayout>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:gravity="right"
            android:layout_marginRight="20dp"
            android:orientation="vertical">
            <ImageView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:background="@drawable/biz_pc_plugin_weather_duoyun"/>
            <TextView
                android:id="@+id/weather_layout_weatherwind"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/weather_layout_desc"
                android:textSize="18sp"/>
            <TextView
                android:id="@+id/weather_layout_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/weather_layout_location"
                android:textSize="18sp"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/weather_layout_desc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/dushu"
            android:orientation="vertical">
            <TextView
                android:id="@+id/weather_layout_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/weather_layout_time"
                android:textSize="18sp"/>
            <TextView
                android:id="@+id/weather_layout_pm"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/weather_layout_pm"
                android:textSize="18sp"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/weather_layout_one_images"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/weather_layout_desc"
            android:layout_marginTop="50dp"
            android:layout_marginLeft="-10dp"
            android:orientation="horizontal">
            <LinearLayout
                android:id="@+id/weather_layout_search"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="1">
                <ImageButton
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:scaleType="fitXY"
                    android:background="@drawable/ic_main_more_menu_search_icon"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="18sp"
                    android:text="@string/weather_layout_search_txt"/>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/weather_layout_headline"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="1">
                <ImageButton
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:scaleType="fitXY"
                    android:background="@drawable/ic_main_more_menu_headline_icon"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="18sp"
                    android:text="@string/weather_layout_headline_txt"/>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/weather_layout_offline"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_weight="1">
                <ImageButton
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:scaleType="fitXY"
                    android:background="@drawable/ic_main_more_menu_offline_icon"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="18sp"
                    android:text="@string/weather_layout_offline_txt"/>
            </LinearLayout>
        </LinearLayout>
        <LinearLayout
            android:layout_below="@+id/weather_layout_one_images"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="-10dp"
            android:orientation="horizontal">
            <LinearLayout
                android:id="@+id/weather_layout_theme"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="1">
                <ImageButton
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:scaleType="fitXY"
                    android:background="@drawable/ic_main_more_menu_theme_icon"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="18sp"
                    android:text="@string/weather_layout_theme_txt"/>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/weather_layout_scan"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="1">
                <ImageButton
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:scaleType="fitXY"
                    android:background="@drawable/ic_main_more_menu_scan_icon"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="18sp"
                    android:text="@string/weather_layout_scan_txt"/>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/weather_layout_invitation"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_weight="1">
                <ImageButton
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:scaleType="fitXY"
                    android:background="@drawable/ic_main_more_menu_invitation_icon"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="18sp"
                    android:text="@string/weather_layout_invitation_txt"/>
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>


颜色编码格式:#6位十六进制数据比如(#243232)纯粹的RGB(255,255,255)。


如果颜色编码为:#8位十六进制数据,比如(#00232323)后面六位依然是RGB方法。前面的两位就是透明度。00为完全透明,ff为完全不透明。


这个布局其他的就不需要多解释了。下面我们来分析一下,界面打开的过程。

相关文章
|
1月前
|
缓存 API 定位技术
使用Python调用百度地图API实现地址查询
使用Python调用百度地图API实现地址查询
108 0
|
8月前
|
定位技术 API 开发工具
Android 按照步骤接入百度地图API,定位显示不了解决办法
Android 按照步骤接入百度地图API,定位显示不了解决办法
236 0
|
9月前
|
数据可视化 定位技术 API
百度地图开发:海量点、测距以及定位聚合功能
百度地图开发:海量点、测距以及定位聚合功能
217 0
|
9月前
|
JavaScript 前端开发 API
python对接API二次开发高级实战案例解析:百度地图Web服务API封装函数(行政区划区域检索、地理编码、国内天气查询、IP定位、坐标转换)
python对接API二次开发高级实战案例解析:百度地图Web服务API封装函数(行政区划区域检索、地理编码、国内天气查询、IP定位、坐标转换)
235 0
|
9月前
|
移动开发 小程序 JavaScript
微信小程序学习实录6(百度经纬度采集、手动调整精度、H5嵌入小程序、百度地图jsAPI、实时定位、H5更新自动刷新)
微信小程序学习实录6(百度经纬度采集、手动调整精度、H5嵌入小程序、百度地图jsAPI、实时定位、H5更新自动刷新)
134 1
|
4月前
|
存储 Oracle 关系型数据库
百度搜索:蓝易云【oracle dblink mysql查询text无法显示问题】
通过使用 `DBMS_HS_PASSTHROUGH` 包执行 MySQL 查询并返回 CLOB 类型结果,可以解决 Oracle 数据库中无法直接显示 MySQL TEXT 类型数据的问题。
47 0
|
7月前
|
定位技术
|
9月前
|
搜索推荐 数据可视化 JavaScript
数据可视化大屏百度地图绘制行政区域标注实战案例解析(个性化地图、标注、视频、控件、定位、检索)
数据可视化大屏百度地图绘制行政区域标注实战案例解析(个性化地图、标注、视频、控件、定位、检索)
133 1
|
9月前
|
前端开发 定位技术 数据安全/隐私保护
百度地图高级开发:LBS服务实时定位覆盖范围内关键词标注的解决方案(2)
百度地图高级开发:LBS服务实时定位覆盖范围内关键词标注的解决方案(2)
60 0
|
9月前
|
移动开发 定位技术 API
百度地图开发:H5获取GPS-wg84经纬度与百度定位API的偏差测试
百度地图开发:H5获取GPS-wg84经纬度与百度定位API的偏差测试
143 0