前言:最近计划学习一个商城项目进行开发练手,所以准备写写记录一下,加深一下理解。
(一)
商城的效果界面大概与主流的手机购物app类似,万地高楼平地起,所以第一步先进行主界面的搭建,这边文章先实现底部菜单栏。这篇文章最后的效果图应该是这样:
在这里这个功能主要是用FragmentTabHost和Selector选择器来实现;
有如下几个步骤:
- FragmentTabHost初始化必须调用setup的有参构造方法;
- 设置好Fragment,TabSpec 与 Indicator添加到TabHost;
直接上代码:
主界面的布局文件(activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="liyong.shop.MainActivity">
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<android.support.v4.app.FragmentTabHost
<