整体布局是一个线性布局里面包括两个线性布局,上面的线性布局可以用其他布局替换,这个看个人爱好了;
下面线性布局是四个等分的相对布局,进货单有一个消息提示,所以用相对布局好控制位置;
先看下进货单的布局:
<RelativeLayout
android:id="@+id/shopping_cart_page"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1">
<RadioButton
android:id="@+id/shopping_cart_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:button="@null"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_stock_list"
android:gravity="center"
android:text="进货单"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />
<TextView
android:id="@+id/shopping_cart_num"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/shopping_cart_button"
android:layout_alignTop="@id/shopping_cart_button"
android:layout_marginTop="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="99+"
android:textColor="@color/white"
android:textSize="8sp"
/>
</RelativeLayout>
整体布局就不再复制了,因为其他三个和这个一样,只是没有TextView
MainActivity代码:
public class MainActivity extends FragmentActivity implements View.OnClickListener {
private RadioButton btnHome,btnGoods,btnShopCart,btnUserVip;
private RelativeLayout homePage,goodsPage,shoppingPage,usePage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container,new HomeFragment())
.commit();
}
@Override
public void onClick(View v) {
BaseFragment fragment=null;
switch (v.getId()){
case R.id.homepage:
fragment=new HomeFragment();
changeState(true,false,false,false);
break;
case R.id.goods_page:
fragment=new GoodsFragment();
changeState(false,true,false,false);
break;
case R.id.shopping_cart_page:
fragment=new ShoppingFragment();
changeState(false,false,true,false);
break;
case R.id.user_page:
fragment=new UserFragment();
changeState(false,false,false,true);
break;
}
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container,fragment)
.commit();
}
private void changeState(boolean homeB,boolean goodsB,boolean shopB,boolean userB ) {
btnHome.setChecked(homeB);
btnGoods.setChecked(goodsB);
btnShopCart.setChecked(shopB);
btnUserVip.setChecked(userB);
}
private void initView() {
homePage= (RelativeLayout) findViewById(R.id.homepage);
goodsPage= (RelativeLayout) findViewById(R.id.goods_page);
shoppingPage= (RelativeLayout) findViewById(R.id.shopping_cart_page);
usePage= (RelativeLayout) findViewById(R.id.user_page);
btnHome= (RadioButton) findViewById(R.id.home_button);
btnGoods= (RadioButton) findViewById(R.id.goods_button);
btnShopCart= (RadioButton) findViewById(R.id.shopping_cart_button);
btnUserVip= (RadioButton) findViewById(R.id.user_button);
homePage.setOnClickListener(this);
goodsPage.setOnClickListener(this);
shoppingPage.setOnClickListener(this);
usePage.setOnClickListener(this);
}
}
非常简单的实现方式就能实现,当然大家可以进一步的封装;
目前公司正在做的项目就是使用的这个框架;
大家可以根据需求选择,如果没有消息提示可以直接只用这个框架:http://blog.csdn.net/zheng_jiao/article/details/51746915