Android編程實現(xiàn)在底端顯示選項卡的方法
本文實例講述了Android編程實現(xiàn)在底端顯示選項卡的方法。分享給大家供大家參考,具體如下:
1.layout 文件
<?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabHost android:id="@+id/edit_item_tab_host" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp" android:layout_weight="1"> <LinearLayout android:id="@+id/widget_layout_Blue" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="3px" android:paddingRight="3px"> <LinearLayout android:id="@+id/titleLayout_person_check_road_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> <LinearLayout android:id="@+id/layout_person_check_road_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/titleLayout_person_check_road_add" android:layout_alignTop="@id/titleLayout_person_check_road_add" android:orientation="vertical"> </LinearLayout> </RelativeLayout> </LinearLayout> <LinearLayout android:id="@+id/widget_layout_red" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="3px" android:paddingRight="3px"> <LinearLayout android:id="@+id/titleLayout_person_check_road_add1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> <LinearLayout android:id="@+id/layout_person_check_road_add1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/titleLayout_person_check_road_add1" android:layout_alignTop="@id/titleLayout_person_check_road_add1" android:orientation="vertical"> </LinearLayout> </RelativeLayout> </LinearLayout> <LinearLayout android:id="@+id/widget_layout_green" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="3px" android:paddingRight="3px"> <LinearLayout android:id="@+id/titleLayout_person_check_road_add2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> <LinearLayout android:id="@+id/layout_person_check_road_add2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/titleLayout_person_check_road_add2" android:layout_alignTop="@id/titleLayout_person_check_road_add2" android:orientation="vertical"> </LinearLayout> </RelativeLayout> </LinearLayout> <LinearLayout android:id="@+id/widget_layout_yellow" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="3px" android:paddingRight="3px"> <LinearLayout android:id="@+id/titleLayout_person_check_road_add3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> <LinearLayout android:id="@+id/layout_person_check_road_add3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/titleLayout_person_check_road_add3" android:layout_alignTop="@id/titleLayout_person_check_road_add3" android:orientation="vertical"> </LinearLayout> </RelativeLayout> </LinearLayout> </FrameLayout> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0" /> </LinearLayout> </TabHost> </LinearLayout>
2.Java 文件
import android.app.ActivityGroup; import android.graphics.Color; import android.os.Bundle; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.TabHost; import android.widget.TextView; public class TabBottom extends ActivityGroup { public static TabHost myTabhost; private LayoutParams title_params = new LayoutParams(120, 50); private LayoutParams content_params = new LayoutParams(158, 50); private LinearLayout titleLayout, showViewLayout, titleLayout1, showViewLayout1, titleLayout2, showViewLayout2, titleLayout3, showViewLayout3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bottomtab); myTabhost = (TabHost) findViewById(R.id.edit_item_tab_host); myTabhost.setup(this.getLocalActivityManager()); titleLayout = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add); showViewLayout = (LinearLayout) findViewById(R.id.layout_person_check_road_add); titleLayout1 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add1); showViewLayout1 = (LinearLayout) findViewById(R.id.layout_person_check_road_add1); titleLayout2 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add2); showViewLayout2 = (LinearLayout) findViewById(R.id.layout_person_check_road_add2); titleLayout3 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add3); showViewLayout3 = (LinearLayout) findViewById(R.id.layout_person_check_road_add3); myTabhost.addTab(myTabhost .newTabSpec("One") .setIndicator("收件箱", getResources().getDrawable(R.drawable.icon)) .setContent(R.id.widget_layout_Blue)); myTabhost.addTab(myTabhost .newTabSpec("Two") .setIndicator("發(fā)件箱", getResources().getDrawable(R.drawable.icon)) .setContent(R.id.widget_layout_green)); myTabhost.addTab(myTabhost .newTabSpec("Three") .setIndicator("垃圾箱", getResources().getDrawable(R.drawable.icon)) .setContent(R.id.widget_layout_red)); myTabhost.addTab(myTabhost .newTabSpec("Four") .setIndicator("發(fā)送", getResources().getDrawable(R.drawable.icon)) .setContent(R.id.widget_layout_yellow)); showInLayout(); showInLayout1(); showInLayout2(); showInLayout3(); } /* * 填充第一個選項卡頁面 */ private void showInLayout() { for (int i = 0; i < 10; i++) { String condName = "名稱顯示1"; TextView tv = new TextView(this); tv.setTextColor(Color.WHITE); tv.setTextSize(16); tv.setLayoutParams(title_params); tv.setText(condName + ":"); titleLayout.addView(tv); EditText tv1 = new EditText(this); tv1.setTextSize(16); tv1.setLayoutParams(content_params); tv1.setText(condName); showViewLayout.addView(tv1); } } private void showInLayout1() { for (int i = 0; i < 10; i++) { String condName = "名稱顯示2"; TextView tv = new TextView(this); tv.setTextColor(Color.WHITE); tv.setTextSize(16); tv.setLayoutParams(title_params); tv.setText(condName + ":"); titleLayout1.addView(tv); TextView tv1 = new TextView(this); tv1.setTextColor(Color.WHITE); tv1.setTextSize(16); tv1.setLayoutParams(content_params); tv1.setText(condName + ":"); showViewLayout1.addView(tv1); } } private void showInLayout2() { for (int i = 0; i < 10; i++) { String condName = "名稱顯示3"; TextView tv = new TextView(this); tv.setTextColor(Color.WHITE); tv.setTextSize(16); tv.setLayoutParams(title_params); tv.setText(condName + ":"); titleLayout2.addView(tv); TextView tv1 = new TextView(this); tv1.setTextColor(Color.WHITE); tv1.setTextSize(16); tv1.setLayoutParams(content_params); tv1.setText(condName + ":"); showViewLayout2.addView(tv1); } } private void showInLayout3() { for (int i = 0; i < 10; i++) { String condName = "名稱顯示4"; TextView tv = new TextView(this); tv.setTextColor(Color.WHITE); tv.setTextSize(16); tv.setLayoutParams(title_params); tv.setText(condName + ":"); titleLayout3.addView(tv); TextView tv1 = new TextView(this); tv1.setTextColor(Color.WHITE); tv1.setTextSize(16); tv1.setLayoutParams(content_params); tv1.setText(condName + ":"); showViewLayout3.addView(tv1); } } }
效果如下:
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android資源操作技巧匯總》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- android TabHost(選項卡)的使用方法
- android 選項卡(TabHost)如何放置在屏幕的底部
- Android實現(xiàn)底部導(dǎo)航欄功能(選項卡)
- Android TabLayout(選項卡布局)簡單用法實例分析
- Android仿微信底部實現(xiàn)Tab選項卡切換效果
- Android多個TAB選項卡切換效果
- Android基于ViewPager Fragment實現(xiàn)選項卡
- Android利用Fragment實現(xiàn)Tab選項卡效果
- Android組件TabHost實現(xiàn)頁面中多個選項卡切換效果
- Android編程之TabWidget選項卡用法實例分析
- Android實現(xiàn)類似網(wǎng)易新聞選項卡動態(tài)滑動效果
- Android編程實現(xiàn)自定義Tab選項卡功能示例
相關(guān)文章
Android nativePollOnce函數(shù)解析
這篇文章主要介紹了Android nativePollOnce函數(shù)解析的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03Android ActionBar完全解析使用官方推薦的最佳導(dǎo)航欄(下)
這篇文章主要介紹了Android ActionBar完全解析使用官方推薦的最佳導(dǎo)航欄(下) ,需要的朋友可以參考下2017-04-04Android布局控件DrawerLayout實現(xiàn)完美側(cè)滑效果
這篇文章主要為大家詳細介紹了Android布局控件DrawerLayout實現(xiàn)完美側(cè)滑效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-08-08Android開發(fā)中超好用的正則表達式工具類RegexUtil完整實例
這篇文章主要介紹了Android開發(fā)中超好用的正則表達式工具類RegexUtil,結(jié)合完整實例形式分析了Android正則表達式常見操作技巧,包括針對證件號、銀行賬號、手機號、郵編等的正則判斷相關(guān)操作技巧,需要的朋友可以參考下2017-11-11android配合viewpager實現(xiàn)可滑動的標(biāo)簽欄示例分享
本文主要介紹了android實現(xiàn)可滑動的標(biāo)簽欄示例,配合viewpager作為標(biāo)簽欄,且可以設(shè)置每頁顯示的標(biāo)簽個數(shù),超出可滑動顯示,需要的朋友可以參考下2014-02-02