引导页面,多个城市的天气,可以通过滑动来翻阅。

先看下截图:

1、城市天气界面

2、引导界面

应用引导页面

package org.qxj.iweather.page;

import org.qxj.iweather.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ViewFlipper; public class Welcome extends Activity { private static final String TAG = "Welcome";
private SharedPreferences shared = null;
private SharedPreferences.Editor edit = null;
private LinearLayout layout = null;
private ViewFlipper flip = null;
private LayoutParams match = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
private String isFirst = "false";
private Intent intent = null; class TurnPage implements Runnable { @Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(5000);
TurnToMain();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} } @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.shared = super.getSharedPreferences("IWeather", MODE_PRIVATE);
this.edit = this.shared.edit(); this.layout = new LinearLayout(this);
this.layout.setOrientation(LinearLayout.VERTICAL); this.flip = new ViewFlipper(this);
this.layout.addView(this.flip, match);
this.layout.setBackgroundResource(R.drawable.welcome);
super.addContentView(this.layout, match); isFirst = this.shared.getString("isFirst", "true");
Log.i(TAG, "isFirst: " + isFirst);
if ("true".equals(isFirst)) {
this.edit.putString("isFirst", "false");
this.edit.commit();
new Thread(new TurnPage()).start();
} else {
// 进行跳转
TurnToMain();
} } public void TurnToMain() {
// 进行跳转
intent = new Intent(Welcome.this, Main.class);
startActivity(intent);
// 销毁该Activity,返回的时候,不会返回该界面。
this.finish();
} }

主页面

package org.qxj.iweather.page;

import org.qxj.iweather.R;
import org.qxj.iweather.Contents.IWeather;
import org.qxj.iweather.net.HttpHelper; import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout; public class Main extends Activity implements OnGestureListener { private IWeather iWeather = null;
private LinearLayout layout = null;
private GestureDetector detector;
private LayoutParams match = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT); @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.layout = new LinearLayout(this);
detector = new GestureDetector(this);
this.iWeather = new IWeather(this);
this.layout.addView(this.iWeather.flip, match);
this.addContentView(this.layout, match);
iWeather.flip.addView(new PageLayout(this, "101301301"));
iWeather.flip.addView(new PageLayout(this, "101010100"));
iWeather.flip.addView(new PageLayout(this, "101260101"));
iWeather.flip.addView(new PageLayout(this, "101190501"));
iWeather.flip.addView(new PageLayout(this, "101190101"));
iWeather.flip.addView(new PageLayout(this, "101170101"));
} @Override
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
} @Override
public boolean onDown(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
} @Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
if (e1.getX() - e2.getX() > 80) {
iWeather.flip.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_in));
iWeather.flip.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_out));
iWeather.flip.showNext();
return true;
} else if (e1.getX() - e2.getX() < -80) {
iWeather.flip.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_in));
iWeather.flip.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_out));
iWeather.flip.showPrevious();
return true;
}
return false;
} @Override
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub } @Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
} @Override
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub } @Override
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
} }

自定义的pageLayout

package org.qxj.iweather.page;

import org.qxj.iweather.R;
import org.qxj.iweather.model.Weather;
import org.qxj.iweather.net.HttpHelper; import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast; public class PageLayout extends LinearLayout { private Weather weather = null;
private Context context = null;
private TextView temperature = null;
private TextView city = null;
private TextView statues = null;
private TextView date = null;
public Handler hander = new Handler() { @Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 1:
weather = (Weather) msg.obj;
init();
break;
case 0:
Toast.makeText(context, "数据操作失败!", Toast.LENGTH_SHORT).show();
break;
}
} }; public PageLayout(Context context, String city) {
super(context);
this.context = context;
new Thread(new HttpHelper(city, this)).start();
} public PageLayout(Context context, AttributeSet attrs, String city) {
super(context, attrs);
this.context = context;
new Thread(new HttpHelper(city, this)).start();
} public PageLayout(Context context, AttributeSet attrs, int defStyle, String city) {
super(context, attrs, defStyle);
this.context = context;
new Thread(new HttpHelper(city, this)).start();
} private void init() {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.page_layout, this);
this.temperature = (TextView) findViewById(R.id.tempearture);
this.city = (TextView) findViewById(R.id.city);
this.statues = (TextView) findViewById(R.id.statues);
this.date = (TextView) findViewById(R.id.date); this.temperature.setText(this.weather.getTemp1());
this.city.setText(this.weather.getCity());
this.statues.setText(this.weather.getWeather1());
this.date.setText(this.weather.getDate_y());
this.setBackgroundByWeather(this.weather.getWeather1());
} /**
* 设置屏幕背景
*/
private void setBackgroundByWeather(String w) {
if (w.indexOf("雪") != -1) {
// 有雪的天气
this.setBackgroundResource(R.drawable.snow);
} else if (w.indexOf("雨") != -1) {
// 下雨天
this.setBackgroundResource(R.drawable.rain);
} else if (w.indexOf("晴") != -1) {
// 晴
this.setBackgroundResource(R.drawable.sun);
} else if (w.indexOf("阴") != -1) {
// 阴天
this.setBackgroundResource(R.drawable.water);
} else {
this.setBackgroundResource(R.drawable.sun);
}
} }

完整代码:

http://download.csdn.net/detail/niitqin/6472535

Android 实现简单天气应用的更多相关文章

  1. Android 实现简单音乐播放器(二)

    在Android 实现简单音乐播放器(一)中,我介绍了MusicPlayer的页面设计. 现在,我简单总结一些功能实现过程中的要点和有趣的细节,结合MainActivity.java代码进行说明(写出 ...

  2. Android 实现简单音乐播放器(一)

    今天掐指一算,学习Android长达近两个月了,今天开始,对过去一段时间的学习收获以及遇到的疑难杂症做一些总结. 简单音乐播放器是我自己完成的第一个功能较为完整的APP,可以说是我的Android学习 ...

  3. Android课程---Android Studio简单设置

    Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings-->Appearance-->Theme, ...

  4. Android实现简单音乐播放器(MediaPlayer)

    Android实现简单音乐播放器(MediaPlayer) 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个简单的音乐播放器,要求功能 ...

  5. Android实现简单拨号器

    Android实现简单拨号器 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 代码实现 界面布局只有GridLayout和EditText两个控件,全部 ...

  6. 【转】Android Studio简单设置

    原文网址:http://ask.android-studio.org/?/article/14 Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以 ...

  7. Android发展简单介绍

    Android一词的本义指“机器人”,同一时候也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统.中间件.用户界面和应用软件组成,号称是首个为移动 ...

  8. android JNI 简单demo(2)它JNI demo 写

    android JNI 简单demo(2)它JNI demo 写 一.搭建Cygwin 环境:http://blog.csdn.net/androidolblog/article/details/25 ...

  9. Android Studio简单设置(转)

    Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings --> Appearance --> Th ...

随机推荐

  1. ios本地文件内容读取,.json .plist 文件读写

    ios本地文件内容读取,.json .plist 文件读写 本地文件.json .plist文件是较为常用的存储本地数据的文件,对这些文件的操作也是一种常用的基础. 本文同时提供初始化变量的比较标准的 ...

  2. memcached与redis

    Memcached VS Redis 问题:memcached 与 redis 哪个好? 答:这个问题它依赖与工程类别和它的数据. 1.它们都是内存 key/value 类型的高速与高可用的查询表. ...

  3. Java基础之静态变量

    public class StaticVariable { public static void main(String[] args) { Person p1 = new Person(); Per ...

  4. Linux流量监控工具使用总结 - iftop

    在类Unix系统中可以使用top查看系统资源.进程.内存占用等信息.查看网络状态可以使用netstat.nmap等工具.若要查看实时的网络流量,监控TCP/IP连接等,则可以使用iftop. 一.if ...

  5. 几年前无聊小游戏之作_WEB版本打泡泡

    几年前写的小东西 主要是H5画布的操作,还有个C语言基于WIN SDK开发的版本 找不到代码了 找到了再分享 <!DOCTYPE html> <script src="ga ...

  6. poj 3252 Round Numbers 数位dp

    题目链接 找一个范围内二进制中0的个数大于等于1的个数的数的数量.基础的数位dp #include<bits/stdc++.h> using namespace std; #define ...

  7. linux中的ps命令用法。

    在linux中使用ps命令可以查看有哪些进程在运行和运行的状态.进程是否结束.进程有没有僵尸.哪些进程占用了过多的资源等等. ps命令最常用的是用于监控后台进程的工作情况. 名称:ps 使用权限:所有 ...

  8. SecureCRT, SecureFX连接Linux时中文乱码解决办法

    SecureCRT可以在GUI界面设置,但SecureFX没有设置界面.不过可以直接在配置文件中修改. 1. 找到配置文件夹(选项--全局选项,常规下的配置文件夹),默认是:C:\Documents  ...

  9. Mysql mysqlimport 导入数据

    在mysql 数据库中可以用 mysqlimport 工具来实现数据的导入!mysqlimport 导入数据简单,但是这个也要满足一定的条件 1.既然是把数据导入到数据库,你总有一个数据库用户账号吧 ...

  10. 在PADS LAYOUT中如何隐藏不需要的鼠线?

    如下图示,将net GPR_0的鼠线隐藏. 鼠标右键,选择网络----选择你要隐藏的网络------右键选择view nets----点击对话框右边View List里你所选的网络-----在右下角t ...