Fragment+FragmentTabHost组件实现常见主页面(仿微信新浪)
2016-09-08 16:32
459 查看
采取的方法是Fragment+FragmentTabHost组件来实现这种常见的app主页面的效果
首先给出main.xml文件
主代码:
就ok啦!
首先给出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啦!
相关文章推荐
- Android Fragment+FragmentTabHost组件实现常见主页面(仿微信新浪)
- 安卓开发复习笔记——Fragment+FragmentTabHost组件(实现新浪微
- 安卓开发复习笔记——Fragment+FragmentTabHost组件(实现新浪微
- Fragment嵌套ViewPager加上RadioButton实现微信页面滑动点击效果
- Viewpage和Fragment实现页面切换,微信界面
- ViewPager实现TabHost动态添加、删除Fragment,用红色小圆球指示当前页面
- Fragment+ViewPager 实现仿微信页面
- android TabHost+Fragment实现页面切换时遇到的问题
- Fragment+FragmentTabHost组件(实现新浪微博底部栏)
- Android组件TabHost实现页面中多个选项卡切换效果
- 安卓开发笔记——Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
- 转-Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
- FragmentTabHost+Fragment实现选项卡页面
- 微信小程序自定义组件的实现方法及自定义组件与页面间的数据传递问题
- FragmentTabHost组件,创建,实现,切换事件
- FragmentTabHost、Fragment实现底部点击切换Tab页面
- 仿新浪热门微博页面动态添加Tab标签与Fragment联动的实现
- (4.1.8.3)【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- 安卓开发复习笔记——Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
- ViewPager实现TabHost动态添加、删除Fragment,用红色小圆球指示当前页面