学习Android之第六个小程序新浪微博(二)(ListView和TabActivity)
效果图例如以下:
选项卡的使用:
1.继承TabActivity
2.声明TabHost变量,通过方法getTabHost()获取并赋值。
(TabHost tabHost =getTabHost() ;)
3.在xml文件里,创建TabHost组件和TabWidget组件。而且TabHost组件的id属性必须是: android:id="@android:id/tabhost" ,
TabWidgett组件的id属性必须是:android:id="@android:id/tabs"。
一共同拥有三个activity,BlogActivity.java、MyTabActivity.java、TestActivity.java。四个xml文件,activity_blog.xml、activity_mytab.xml、activity_test.xml、blog.xml。
MyTabActivity.java
package cn.edu.bzu.micro_blog.activity; import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec; public class MyTabActivity extends TabActivity { //继承TabActivity TabHost tabHost;
TabSpec tabSpec01,tabSpec02;
Intent intent01,intent02;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mytab); tabHost=getTabHost(); //获取tabHost
intent01 = new Intent(this, BlogActivity.class);
intent02 = new Intent(this, TestActivity.class); tabSpec01 = tabHost.newTabSpec("system").setIndicator("Blog",null). //创建选项,选项卡的名称为Blog,
//null的一项是设置选项的图标, 能够通过Resources来获取图片。
setContent(intent01); //设置要显示的页面,也能够是组件。 tabSpec02 = tabHost.newTabSpec("hardware").setIndicator("Test",null).
setContent(intent02); tabHost.addTab(tabSpec01); //加入
tabHost.addTab(tabSpec02);
// 设置默认选中的选项卡为第1个
tabHost.setCurrentTab(0); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.first, menu);
return true;
} }
BlogActivity.java
package cn.edu.bzu.micro_blog.activity; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter; public class BlogActivity extends Activity {
private ListView listView;
List<Map<String, ?>> data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blog); listView = (ListView)findViewById(R.id.lv);
SimpleAdapter simpleAdapter = new SimpleAdapter(BlogActivity.this, getData(), R.layout.blog, new String[]{
"name","address","photo"}, new int[]{R.id.name,R.id.wenzi,R.id.photo}); listView.setAdapter(simpleAdapter); } public List<Map<String, ?>> getData() {
data = new ArrayList<Map<String, ? >>();
Map<String, Object> data01 = new HashMap<String, Object>();
data01.put("name", "张三");
data01.put("address", "近期学习了ListView组件,于是就模仿了一下腾讯微博的样式.看起来效果不错");
data01.put("photo",R.drawable.aa);
data.add(data01);
data01 = new HashMap<String, Object>();
data01.put("name", "李四");
data01.put("address", "仅仅是模仿,全都是硬编码,静态的,谢谢赞赏");
data01.put("photo",R.drawable.th);
data.add(data01);
return data;
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
TestActivity.java 仅仅有一个TextView。在这我就不上代码了。
activity_mytab.xml
<? xml version="1.0" encoding="utf-8"?>
<!-- android:id="@android:id/tabhost" 这句是特定的 -->
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- android:id="@android:id/tabs"同上 -->
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="bottom"/> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout> </TabHost>
activity_blog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BlogActivity" > <ListView
android:id="@+id/lv"
android:layout_marginTop="50dp"
android:layout_height="match_parent"
android:layout_width="match_parent"> </ListView> </RelativeLayout>
blog.xml
<? xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ImageButton
android:id="@+id/photo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:src="@drawable/th" /> <TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/photo"
android:text="" /> <TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="20dp"
android:text="1分钟前" /> <TextView
android:id="@+id/wenzi"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_toRightOf="@id/photo"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:text=""/> </RelativeLayout>
学习Android之第六个小程序新浪微博(二)(ListView和TabActivity)的更多相关文章
- 自动批改android模拟器的imei的小程序 和 下载各个版本SDK Tools及ADT
ADT 22.6.0版本的下载路径是:http://dl.google.com/android/ADT-22.6.0.zip ADT22.6.1版本的下载路径是:http://dl.google.co ...
- 关于微信小程序获取二维码的踩坑记录
1.踩坑需求:获取小程序的二维码 2.踩坑接口: https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN3 踩坑代码 pu ...
- 微信小程序配置二
tabBar 客户端窗口底部的tab页面切换,只能配置最好两个.最多5个tab 属性说明: 属性 类型 必填 默认值 描述 color HexColor 是 tab上的文字默认颜色 selectedC ...
- 手持式停车收费管理系统全套案例,支持车牌识别,包含了android版app,微信小程序查询,响应式管理后台,云端大数据存储
先展示几个app效果图片吧,使用起来非常方便,关联了机器的快捷键操作,操作速度提高了不少,摄像头车牌自动识别,车牌识别无网络情况下离线也可以使用 再来一张后台截图,停车场信息完整显示,今日数据实时 ...
- 微信小程序学习笔记(1)-微信小程序样式设置逻辑
1.微信小程序的样式设置统一在每一页的.wxss的样式文件中,所有的样式设置代码统一写入这个文件中: 2.样式主要是通过.wxml里面控件的“class”属性来调用,此处调用会有几个细节要注意: 1) ...
- 小程序学习三 一切的开始app() 小程序的注册
现在打开 app.js //app.js App({ onLaunch(options) { //小程序初始化 // console.log("小程序初始化", options) ...
- 微信小程序入门二
# 微信小程序开发实战 ## 准备 ### 课程概要 - 微信小程序基本介绍- 开发环境及工具的安装配置- 微信小程序的设计规范- 微信小程序基本结构分析- WXML和WXSS语法规范- 微信小程序A ...
- 微信小程序测试二三事
微信小程序虽是微信推出的新形态的产品,但是在测试思路上跟其他的传统测试,大相径庭.既然大相径庭,那我们该如何测试呢. 功能测试功能测试跟传统的web功能测试一样,不是app的功能测试哦.这是因为小程序 ...
- 微信小程序笔记<二>认识app.json
*.json文件在小程序开发中必不可少,从 app.json 开始认识小程序中的配置文件*.json: app.json 为小程序必须文件,它不仅作为配置文件管理着小程序的UI还充当着路由器的功能: ...
随机推荐
- ORACLE常用修改字段脚本
describe employees; = select column_name,data_type,nullable,data_length,data_ precision,data_scale f ...
- django的rest framework框架——分页、视图、路由、渲染器
一.rest framework的分页 1.使用rest framework内置类PageNumberPagination实现分类 from django.conf.urls import url f ...
- 大数据学习——sql练习
1. 现有如下的建表语句和数据: 建表语句 create table student(Sno int,Sname string,Sex string,Sage int,Sdept string)row ...
- apache2虚拟主机实现一个服务器绑定多个域名
1.apache2的配置 首先要配置好apache2,如果未配置,请参考我之前的博文:lamp的配置 2.域名的解析 将全部域名的www和@的A记录解析到云服务器的IP 3.虚拟主机的配置 1.配置h ...
- 2017 Wuhan University Programming Contest (Online Round) D. Events,线段树区间更新+最值查询!
D. Events 线段树区间更新查询区间历史最小值,看似很简单的题意写了两天才写出来. 题意:n个数,Q次操作,每次操作对一个区间[l,r]的数同时加上C,然后输出这段区间的历史最小值. 思路:在线 ...
- 九度oj 题目1467:二叉排序树
题目描述: 二叉排序树,也称为二叉查找树.可以是一颗空树,也可以是一颗具有如下特性的非空二叉树: 1. 若左子树非空,则左子树上所有节点关键字值均不大于根节点的关键字值: 2. 若右子树 ...
- log日志,crontab
定期备份mysql的log日志文件,保留一个月 将文件压缩为gzip格式,节省空间,备份到/home/shell/myqsl_back/目录下,保留一个月mysql_backup备份的脚本 #!/bi ...
- apache kafka参考
apache kafka参考 消息队列分类: 点对点: 消息生产者生产消息发送到queue中,然后消息消费者从queue中取出并且消费消息.这里要注意: 消息被消费以后,queue中不再有存储,所以 ...
- Redis的持久化——AOF
上一篇博文给大家介绍了redis持久化的方式之一RDB,其中说到过RDB的缺陷是可能会导致数据丢失严重,所以redis的作者 由于强迫症又开发出了AOF来你补这一不足.好接下来我将为大家介绍AOF. ...
- [USACO5.3]Big Barn (动态规划)
题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N x N 的方格.输入数据中包括有树的 ...