android+仿微信框架,Android Fragment+FragmentTabHost组件实现常见主页面(仿微信新浪)...

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

首先给出main.xml文件

android:orientation="vertical" android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/realtabcontent"

android:layout_width="fill_parent"

android:layout_height="0dip"

android:layout_weight="1"

android:background="@color/white" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="bottom"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="1px"

android:background="@color/color_home_tab_line" />

android:id="@android:id/tabhost"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="@color/et_divider_disable">

android:id="@android:id/tabcontent"

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_weight="0" />

主代码:

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;

}

}

通过以上文章,希望能帮助到大家,谢谢大家对本站的支持!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值