采取的方法是Fragment+FragmentTabHost组件来实现这种常见的app主页面的效果

首先给出main.xml文件

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="@color/white" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical"> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/color_home_tab_line" /> <android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/et_divider_disable"> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost> </LinearLayout>
</LinearLayout>

主代码:

 public class MainActivity
{ @ViewInject(android.R.id.tabhost)
private FragmentTabHost mTabHost;
private LayoutInflater layoutInflater; private int mImageViewArray[] = {R.drawable.home_tab1, R.drawable.home_tab2, R.drawable.home_tab3, R.drawable.home_tab4};
private String mTextviewArray[] = {"首页", "圈子", "资讯","个人中心"};
private Class fragmentArray[] = {Fragment1.class, Fragment2.class, Fragment3.class,Fragment4.class}; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
} @Override
protected void init() {
// list=new JSONArray();
layoutInflater=LayoutInflater.from(this);
initTabHost();//初始化底部菜单
} /**
* 初始化底部工具栏
*/
private void initTabHost() {
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
int count = fragmentArray.length;
for (int i = 0; i < count; i++) {
TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i])
.setIndicator(getTabItemView(i));
mTabHost.addTab(tabSpec, fragmentArray[i], null);
mTabHost.getTabWidget().getChildAt(i)
.setBackgroundResource(R.color.white);
}
mTabHost.setCurrentTabByTag(mTextviewArray[0]);
mTabHost.getTabWidget().setDividerDrawable(null);
} /**
* 项的样式
* @param index 第几个
* @return 每一个Tab样式
*/
private View getTabItemView(int index) {
View view = layoutInflater.inflate(R.layout.tab_home_item, null);
ImageView imageView = (ImageView) view.findViewById(R.id.icon);
imageView.setImageResource(mImageViewArray[index]);
TextView textView = (TextView) view.findViewById(R.id.name);
textView.setText(mTextviewArray[index]);
return view;
} }

就ok啦!

Fragment+FragmentTabHost组件实现常见主页面(仿微信新浪)的更多相关文章

  1. 转-Fragment+FragmentTabHost组件(实现新浪微博底部菜单)

    http://www.cnblogs.com/lichenwei/p/3985121.html 记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果, ...

  2. 安卓开发笔记——Fragment+FragmentTabHost组件(实现新浪微博底部菜单)

    记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果,但作为学习,还是需要来了解下这个新引入类FragmentTabHost 之前2篇文章的链接: 安 ...

  3. Android中Fragment和ViewPager那点事儿(仿微信APP)

    在之前的博文<Android中使用ViewPager实现屏幕页面切换和引导页效果实现>和<Android中Fragment的两种创建方式>以及<Android中Fragm ...

  4. Android仿微信图片上传,可以选择多张图片,缩放预览,拍照上传等

    仿照微信,朋友圈分享图片功能 .可以进行图片的多张选择,拍照添加图片,以及进行图片的预览,预览时可以进行缩放,并且可以删除选中状态的图片 .很不错的源码,大家有需要可以下载看看 . 微信 微信 微信 ...

  5. Vue3.0聊天室|vue3+vant3仿微信聊天实例|vue3.x仿微信app界面

    一.项目简介 基于Vue3.0+Vant3.x+Vuex4.x+Vue-router4+V3Popup等技术开发实现的仿微信手机App聊天实例项目Vue3-Chatroom.实现了发送图文表情消息/g ...

  6. 安卓开发笔记——Fragment+ViewPager组件(高仿微信界面)

    什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开发复习笔记——ViewPager组件(仿微信引导界面)>,不清楚的朋友可以看看,这里就不再 ...

  7. 转-Fragment+ViewPager组件(高仿微信界面)

    http://www.cnblogs.com/lichenwei/p/3982302.html 什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开 ...

  8. 转-ViewPager组件(仿微信引导界面)

    http://www.cnblogs.com/lichenwei/p/3970053.html 这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager ...

  9. 安卓开发笔记——ViewPager组件(仿微信引导界面)

    这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager 什么是ViewPager? ViewPager是安卓3.0之后提供的新特性,继承自ViewGro ...

随机推荐

  1. ld - linker

    [ld - linker] NAME ld -- linker SYNOPSIS ld files...  [options] [-o outputfile] DESCRIPTION The ld c ...

  2. C++11变长参数模板

    [C++11变长参数模板] C++03只有固定模板参数.C++11 加入新的表示法,允许任意个数.任意类别的模板参数,不必在定义时将参数的个数固定. 实参的个数也可以是 0,所以 tuple<& ...

  3. Maven+Spring Batch+Apache Commons VF学习

    Apache Commons VFS资料:例子:http://www.zihou.me/html/2011/04/12/3377.html详细例子:http://p7engqingyang.iteye ...

  4. LeetCode104: Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  5. Codeforces 707 E. Garlands (二维树状数组)

    题目链接:http://codeforces.com/problemset/problem/707/E 给你nxm的网格,有k条链,每条链上有len个节点,每个节点有一个值. 有q个操作,操作ask问 ...

  6. poj1061 青蛙的约会 扩展欧几里德的应用

    这个题解得改一下,开始接触数论,这道题目一开始是看了别人的思路做的,后来我又继续以这种方法去做题,发现很困难,学长告诉我先看书,把各种词的定义看懂了,再好好学习,我做了几道朴素的欧几里德,尽管是小学生 ...

  7. OpenSSL命令---ciphers

    用途: 指令是用来展示用于SSL加密算法的工具.它能够把所有openssl支持的加密算法按照一定规律排列(一般是加密强度).这样可以用来做测试工具,决定使用什么加密算法. 用法: openssl ci ...

  8. CCPC总结

    [印象·南阳] 10月15日出发,威海—烟台—郑州—南阳,一路上欢声笑语,从谁是卧底到各类纸牌游戏,也是欢乐.在从郑州到南阳的车上,对面的好像是河南当地的学长,感叹道工作不易的样子,说还是学生时代最为 ...

  9. hdoj 5349 MZL's simple problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5349 #include<stdio.h> int main(){ int cnt; int ...

  10. android ListView进阶

    ListView 1.在android 开发中很多时候都要用到ListView的这个控件的,但用这个控件的时候会遇到一些问题,如在ListView中有Button按钮,就需要将按钮的监听事件给分离出来 ...