实现这个布局有很多种方式,比如用Tabhost实现
XML代码如下:
<?xml version="1.0" encoding="UTF-8"?> <!-- TabHost组件id值不可变 --> <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:orientation="vertical" > <!-- TabWidget组件id值不可变 --> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" > </TabWidget> <!-- FrameLayout布局,id值不可变 --> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@android:id/tabs" > </FrameLayout> </RelativeLayout> </TabHost>
Activity页面代码如下:
package com.cxt.devicetest; import android.os.Bundle; import android.app.TabActivity; import android.content.Intent; import android.view.LayoutInflater; import android.view.Menu; import android.view.Window; import android.view.WindowManager; import android.widget.TabHost; public class MainActivity extends TabActivity { private TabHost tabHost; private Intent system_Information_intent; // 系统信息 private Intent hardware_Information_intent; // 硬件信息 private Intent software_Information_intent; // 软件信息 private Intent runtime_Information_intent; // 运行时信息 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // // 隐去标题栏(应用程序的名字) // this.requestWindowFeature(Window.FEATURE_NO_TITLE); // //隐去状态栏部分(电池等图标和一切修饰部分) // this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, // WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); tabHost = getTabHost(); initIntent(); addSpec(); } /** * * 初始化各个tab标签对应的intent */ private void initIntent() { system_Information_intent = new Intent(this, SystemActivity.class); hardware_Information_intent = new Intent(this, HardWareActivity.class); software_Information_intent = new Intent(this, SoftwareActivity.class); runtime_Information_intent = new Intent(this, RuntimeActivity.class); } /** * * 为tabHost添加各个标签项 */ private void addSpec() { tabHost.addTab(this.buildTagSpec("tab_system", R.string.system, R.drawable.menu_about_icon, system_Information_intent)); tabHost.addTab(this.buildTagSpec("tab_hardware", R.string.hardware, R.drawable.menu_map_icon, hardware_Information_intent)); tabHost.addTab(this.buildTagSpec("tab_software", R.string.software, R.drawable.menu_forum_icon, software_Information_intent)); tabHost.addTab(this.buildTagSpec("tab_runtime", R.string.runtime, R.drawable.menu_service_icon, runtime_Information_intent)); } /** * * 自定义创建标签项的方法 * * @param tagName * 标签标识 * * @param tagLable * 标签文字 * * @param icon * 标签图标 * * @param content * 标签对应的内容 * * @return */ private TabHost.TabSpec buildTagSpec(String tagName, int tagLable, int icon, Intent content) { return tabHost .newTabSpec(tagName) .setIndicator(getResources().getString(tagLable), getResources().getDrawable(icon)).setContent(content); } @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; } }
你把代码copy上去试试看,一定可以成功的!我亲自写的代码。