ANDROID学习记录(1)--FragmentTabHost 和Fragment的切换。
来源:互联网 发布:信号强度测试软件 编辑:程序博客网 时间:2024/06/06 19:48
当主页使用Activity的intent跳转时,会产生activity的堆栈,对于首页和切换频繁的页面界面呈现效果会非常的差。
可以通过Fragment进行切换。
Android加入了FragmentTabHost的控件,可以简单的实现Fragment的切换并实现Fragment切换时的监听。
布局代码如下:
<FrameLayout android:id="@+id/realtabcontent" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /><android.support.v4.app.FragmentTabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content" > <FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0" /></android.support.v4.app.FragmentTabHost>
主java程序的呈现
private Class mFragmentArray[] = {HomeActivityFragment.class, FileMainActivity.class, DeviceConfigFragment.class};
private String mTextArray[] = {"首页", "传输", "我的"};
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); initView();}/** * 初始化组件 */private void initView() { mLayoutInflater = LayoutInflater.from(this); // 找到TabHost mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); // 得到fragment的个数 int count = mFragmentArray.length; for (int i = 0; i < count; i++) { // 给每个Tab按钮设置图标、文字和内容 TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTextArray[i]) .setIndicator(getTabItemView(i)); // 将Tab按钮添加进Tab选项卡中 mTabHost.addTab(tabSpec, mFragmentArray[i], null); // 设置Tab按钮的背景 mTabHost.getTabWidget().getChildAt(i); } mTabHost.setOnTabChangedListener( new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { //do what you want to do } } );}/** * 给每个Tab按钮设置图标和文字 */private View getTabItemView(int index) { View view = mLayoutInflater.inflate(R.layout.activity_home_bottombar, null); ImageView imageView = (ImageView) view.findViewById(R.id.imageview); imageView.setImageResource(mImageArray[index]); TextView textView = (TextView) view.findViewById(R.id.textview); textView.setText(mTextArray[index]); return view;}
0 0
- ANDROID学习记录(1)--FragmentTabHost 和Fragment的切换。
- android fragment+ FragmentTabHost+viewpager 切换状态不保存的问题
- FragmentTabHost+Fragment实现底部菜单的切换
- 『ANDROID』FragmentTabHost的应用(fragment学习系列稿件之二)
- Android学习之FragmentTabHost配合Fragment使用
- android FragmentTabHost切换Fragment时避免UI重新加载
- Fragment和FragmentTabHost的混合使用
- FragmentTabHost中切换Fragment状态保存的几种方法
- FragmentTabHost中切换Fragment保存状态的2种方法
- Android FragmentTabHost嵌套(ViewPager+Fragment)问题
- Android Fragment FragmentTabHost问题
- Android--FragmentTabHost+Fragment
- FragmentTabHost切换Fragment,与ViewPager切换Fragment时重新onCreateView的问题
- 主界面的Fragment切换之使用FragmentTabHost配合切换Fragment
- FragmentTabHost切换Fragment避免重新加载Fragment,即重复调用Fragment的onCreateView。
- FragmentTabHost+Fragment的使用
- FragmentTabHost切换Fragment时避免重复加载UI(ViewPager切换Fragment时也适用)
- FragmentTabHost切换Fragment时避免重复加载UI(ViewPager切换Fragment时也适用)
- 学习python
- 1214-1220———关于cron与日志上传
- easyui datagrid fitColumns 不生效
- 【算法拾遗(java描述)】--- 选择排序(直接选择排序、堆排序)
- 【实验二】make lba minicom
- ANDROID学习记录(1)--FragmentTabHost 和Fragment的切换。
- Localsocket -2
- Fragment笔记
- iOS SDK:iOS调试技巧
- #研发解决方案介绍#Tracing(鹰眼)
- ios学习----- mjRefresh使用指南
- Objective-c语言_SNottification(通知)
- gdut月赛A: GG和女神(好题)
- git重新初始化远程仓库