选项卡组件和ListView组件结合模拟新浪微博
来源:互联网 发布:centos 7登录 编辑:程序博客网 时间:2024/05/18 04:55
选项卡组件和ListView组件结合模拟新浪微博
效果图:
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;@Overrideprotected 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 {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_three);}@Overridepublic 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 {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_two);}@Overridepublic 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>
0 0
- 选项卡组件和ListView组件结合模拟新浪微博
- 选项卡组件和ListView组件结合模拟新浪微博
- 任务2:选项卡组件和ListView组件结合模拟新浪微博
- Android程序——选项卡组件和ListView组件结合模拟新浪微博
- 选项卡组件和ListView组件结合模拟新浪微博
- 选项卡组件和ListView组件结合模拟新浪微博
- Android UI 设计 选项卡组件和ListView组件结合模拟新浪微博
- 《选项卡组件和ListView组件结合模拟新浪微博》
- ListView组件的应用(模拟新浪微博界面)
- Tab组件和ListView组件结合
- listview组件的应用模拟微博
- Tab组件和其他组件结合使用(含ListView)
- TabHost组件和ListView组件的结合使用
- 动态组件(可模拟选项卡)
- listview组件的应用—模拟微博
- android: listview组件的应用-模拟微博
- 用友盟社会化组件,分享到微信和新浪微博
- Android学习12——Tab组件和ListView组件结合
- 谈谈如何学习嵌入式Linux(一)
- hdu 1081 To The Max(最大子矩阵和)
- module_init解析
- 玩转html5(一)-----盘点html5新增的那些酷酷的input类型和属性
- Windows Users and Their Misconceptions About Linux
- 选项卡组件和ListView组件结合模拟新浪微博
- C语言指针转换为intptr_t类型
- 诺基亚
- 同步代码块和方法wait()、notify()的深入解析
- 使图片自动移动的方法
- 转载:Ubuntu 12.04下安装配置Python 2.7集成开发环境Eric4
- Quartz 框架 教程(中文版)2.2.x 之第四课 更多关于Triggers
- 设计模式之6大原则(6)开闭原则
- OCP-1Z0-051 第40题 视图的注意事项