选项卡组件和ListView组件结合模拟新浪微博
2014-04-27 10:39
357 查看
选项卡组件和ListView组件结合模拟新浪微博
效果图:
![](http://img.blog.csdn.net/20140427103329343?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAwMDQzNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
MainActivity.java:
one two three:
activity_main.xml
activity_one.xml
activity_two.xml
activity_three.xml
blog.xml
strings.xml
效果图:
MainActivity.java:
package com.example.task2.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 MainActivity extends TabActivity { TabHost tabHost; TabSpec tabSpec01,tabSpec02,tabSpec03; Intent intent01,intent02,intent03; @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tab); tabHost=getTabHost(); intent01 = new Intent(this, One.class); intent02 = new Intent(this, Two.class); intent03= new Intent(this, Three.class); tabSpec01 = tabHost.newTabSpec("system").setIndicator("Blog",null). setContent(intent01); tabSpec02 = tabHost.newTabSpec("hardware").setIndicator("Test",null). setContent(intent02); tabSpec03 =tabHost.newTabSpec("apple").setIndicator("bag",null). setContent(intent03); tabHost.addTab(tabSpec01); tabHost.addTab(tabSpec02); tabHost.addTab(tabSpec03); tabHost.setCurrentTab(0); } }
one two three:
package com.example.task2.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 One extends Activity { private ListView listView; List<Map<String, ?>> data; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_one); listView = (ListView)findViewById(R.id.lv); SimpleAdapter simpleAdapter = new SimpleAdapter(One.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", "小a"); data01.put("address", "夜空中最亮的星"); data01.put("photo",R.drawable.a); data.add(data01); data01 = new HashMap<String, Object>(); data01.put("name", "小b"); data01.put("address", "夜空中最亮的星"); data01.put("photo",R.drawable.b); data.add(data01); data01 = new HashMap<String, Object>(); data01.put("name", "小c"); data01.put("address", "夜空中最亮的星"); data01.put("photo",R.drawable.c); data.add(data01); data01 = new HashMap<String, Object>(); data01.put("name", "小d"); data01.put("address", "夜空中最亮的星"); data01.put("photo",R.drawable.b); data.add(data01); return data; } }
package com.example.task2.activity; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class Three extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_three); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.three, menu); return true; } }
package com.example.task2.activity; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class Two extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_two); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.two, menu); return true; } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <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" > <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_marginTop="50dp" android:layout_height="fill_parent" /> </RelativeLayout> </TabHost>
activity_one.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=".MainActivity" > <ListView android:id="@+id/lv" android:layout_height="match_parent" android:layout_width="match_parent"> </ListView> </RelativeLayout>
activity_two.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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Two" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
activity_three.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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Three" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </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" /> <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_toRightOf="@id/name" android:layout_marginLeft="130dp" 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>
strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">03UI_task1</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string name="title_activity_one">One</string> <string name="title_activity_two">Two</string> <string name="title_activity_three">Three</string> </resources>
相关文章推荐
- python实现sublime3的less编译插件示例
- 解决 Android 双卡双待识别
- 代码中引用res里的颜色、图片
- asp.net 连接sql server 2005 数据库的设置
- 转载:Ubuntu 12.04下安装配置Python 2.7集成开发环境Eric4
- time.setToNow() 取当前时间,月份有误
- 诺基亚
- C语言指针转换为intptr_t类型
- 使图片自动移动的方法
- adb报错:The connection to adb is down, and a severe&nbs
- HDU 2196 Computer
- Windows Users and Their Misconceptions About Linux
- mongodb 数据库 第一章 安装
- module_init解析
- Ubuntu Linux下通过代理(proxy)使用git上github.com
- 谈谈如何学习嵌入式Linux(一)
- 线程的解读
- OC基础—protocol协议
- 微软公司等数据结构+算法面试100题(第1-100题)全部出炉
- Cocos2dx中获取时间