学习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还充当着路由器的功能: ...
随机推荐
- Hive中文注释乱码解决方案
本文来自网易云社区 作者:王潘安 快速解决方法 目前的hive客户端在执行desc tablexxx和show create table xxx命令的时候,字段的中文注释会出现乱码情况,如(????) ...
- Appium自动化-基于java的环境搭建
引言 自动化测试框架搭建主要分为以下几个方面的下载安装及环境配置: 1.jdk 2. adt 3. appium 4. testng插件 工具链接: https://pan.baidu.com/s/1 ...
- xfce-OpenVAS自动化安全风险评估指南
1. 登录系统 在客户端,打开浏览器,在地址栏输入https://IP:9392/ 看到如下界面: 我们要信任此网站,点击继续浏览此网站,进入系统登录界面,如下图: 输入我提供的通用登录账号:wdl ...
- 如何诊断RAC系统中的'gc cr multi block request'?
'gc cr multi block request' 是RAC数据库上比较常见的一种等待事件,在RAC 上进行全表扫描(Full Table Scan)或者全索引扫描(Index Fast Full ...
- 【Luogu】P3856公共子串(DP)
题目链接 DP.设last[i][j]是第i个串字符'j'所在的最后的位置,f[i][j][k]是第一个串匹配到i,第二个串匹配到j,第三个串匹配到k,最多的公共子串数. 那么我们三重循环i.j.k, ...
- Ignite集成Spark之IgniteDataFrames
下面简要地回顾一下在第一篇文章中所谈到的内容. Ignite是一个分布式的内存数据库.缓存和处理平台,为事务型.分析型和流式负载而设计,在保证扩展性的前提下提供了内存级的性能. Spark是一个流式数 ...
- 二分图最小覆盖的Konig定理及其证明,最小的覆盖证明
[转http://www.cppblog.com/abilitytao/archive/2009/09/02/95147.html -> http://yejingx.ycool.com/p ...
- 【C++】DLL内共享数据区在进程间共享数据(重要)
因项目需要,需要在DLL中共享数据,即DLL中某一变量只执行一次,在运行DLL中其他函数时该变量值不改变:刚开始想法理解错误,搜到了DLL进程间共享数据段,后面发现直接在DLL中定义全局变量就行,当时 ...
- hdu 1717
小数化分数2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- 简单说明PHP的垃圾收集机制是怎样的?
腾讯 对变量有个引用计数,计数到0时变量被销毁. ———————————————————————— 每一种语言都有自己的自动垃圾回收机制,让程序员不必过分关心程序内存分配,但是在OOP中,有些对象需要 ...