android从不同的layout添加tab页内容_tabhost
16lz
2021-01-23
从不同的layout添加tab也内容(tabcontent)<!--这里是layout.mian--><?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent" android:layout_height="fill_parent"><!--tab1的布局 --><LinearLayout android:id="@+id/tab1" android:layout_width="fill_parent"android:layout_height="fill_parent" androidrientation="vertical"><TextView android:text="result" android:id="@+id/result"android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView></LinearLayout><!--tab2的布局 --><LinearLayout android:id="@+id/tab2" android:layout_width="fill_parent"android:layout_height="fill_parent" androidrientation="vertical"><AnalogClock android:id="@+id/widget36"android:layout_width="wrap_content" android:layout_height="wrap_content"></AnalogClock></LinearLayout><!--tab3的布局 --><LinearLayout android:id="@+id/tab3" android:layout_width="fill_parent"android:layout_height="fill_parent" androidrientation="vertical"><RadioGroup android:id="@+id/widget43"android:layout_width="166px" android:layout_height="98px"androidrientation="vertical"><RadioButton android:id="@+id/widget44"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="RadioButton"></RadioButton><RadioButton android:id="@+id/widget45"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="RadioButton"></RadioButton></RadioGroup></LinearLayout></FrameLayout><!--这里是layout.newgallery--><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" androidrientation="vertical" > <TextView android:text="result33" android:id="@+id/result33"android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView></LinearLayout><!--这里是Main.java-->package com.baotab;import android.app.TabActivity;import android.os.Bundle;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.widget.TabHost;import android.widget.TabHost.TabContentFactory;public class Main extends TabActivity implements TabContentFactory {/** Called when the activity is first created. */private LayoutInflater inflater;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setTitle("Tab测试");TabHost tabHost = getTabHost();LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true);inflater = LayoutInflater.from(this); //创建inflatertabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(R.id.tab1));tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab2").setContent(R.id.tab2));tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3").setContent(R.id.tab3));tabHost.addTab(tabHost.newTabSpec("tab44").setIndicator("tab42").setContent(this));}@Overridepublic View createTabContent(String paramString) {View view = null;view = inflater.inflate(R.layout.newgallery, null);Log.d("tabtest", "4");return view;};}
更多相关文章
- Android 之 四大组件、六大布局、五大存储
- Android横竖屏加载不同布局的适配方案
- Android布局LinearLayout+RelativeLayout知识点概括
- Android全屏时软键盘遮住输入框修改布局解决方案
- RelativeLayout相对布局方法总结
- Android测试框架或者工具对比