Android Fragment+FragmentTabHost組件實(shí)現(xiàn)常見主頁(yè)面(仿微信新浪)
采取的方法是Fragment+FragmentTabHost組件來實(shí)現(xiàn)這種常見的app主頁(yè)面的效果
首先給出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[] = {"首頁(yè)", "圈子", "資訊","個(gè)人中心"}; 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); } /** * 項(xiàng)的樣式 * @param index 第幾個(gè) * @return 每一個(gè)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; } }
通過以上文章,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
android自定義View實(shí)現(xiàn)手勢(shì)解鎖
這篇文章主要為大家詳細(xì)介紹了android自定義View實(shí)現(xiàn)手勢(shì)解鎖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06Android下拉刷新完全解析,教你如何一分鐘實(shí)現(xiàn)下拉刷新功能(附源碼)
以下是我自己花功夫編寫了一種非常簡(jiǎn)單的下拉刷新實(shí)現(xiàn)方案,現(xiàn)在拿出來和大家分享一下。相信在閱讀完本篇文章之后,大家都可以在自己的項(xiàng)目中一分鐘引入下拉刷新功能2013-07-07Android自定義View實(shí)現(xiàn)地鐵顯示牌效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)地鐵顯示牌效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11使用RoundedBitmapDrawable生成圓角圖片的方法
由于RoundedBitmapDrawable類沒有直接提供生成圓形圖片的方法,所以生成圓形圖片首先需要對(duì)原始圖片進(jìn)行裁剪,將圖片裁剪成正方形,最后再生成圓形圖片,具體實(shí)現(xiàn)方法,可以參考下本文2016-09-09Android P實(shí)現(xiàn)靜默安裝的方法示例(官方Demo)
這篇文章主要介紹了Android P實(shí)現(xiàn)靜默安裝,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02Android編程實(shí)現(xiàn)向桌面添加快捷方式的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)向桌面添加快捷方式的方法,結(jié)合實(shí)例形式詳細(xì)分析了Android添加桌面快捷方式的操作技巧,需要的朋友可以參考下2016-11-11Android框架Volley使用之Post請(qǐng)求實(shí)現(xiàn)方法
這篇文章主要介紹了Android框架Volley使用之Post請(qǐng)求實(shí)現(xiàn)方法,,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05Android中ListView的幾種常見的優(yōu)化方法總結(jié)
Android中的ListView應(yīng)該算是布局中幾種最常用的組件之一,本篇文章主要做了三種優(yōu)化總結(jié),有興趣的可以了解一下。2017-02-02