欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android簡單實現(xiàn)屏幕下方Tab菜單的方法

 更新時間:2016年08月18日 10:38:04   作者:與時俱進  
這篇文章主要介紹了Android簡單實現(xiàn)屏幕下方Tab菜單的方法,簡單分析了Android實現(xiàn)tab菜單所涉及的界面布局及功能相關操作技巧,需要的朋友可以參考下

本文實例講述了Android簡單實現(xiàn)屏幕下方Tab菜單的方法。分享給大家供大家參考,具體如下:

看到很多熱門的Android程序(如:新浪微博、騰訊微博、京東商城、淘寶、當當?shù)鹊龋┦褂眠x項卡風格作為程序界面的主框架結構,而Android的選項卡控件默認是按鈕在上方的。我在網上看到有多種實現(xiàn)方法,這里提供一種個人覺得比較簡單的。由于我對Android開發(fā)所知甚少,方法的優(yōu)劣目前不好評價,歡迎各位提供更好的思路。

主要原理:設置 TabWidget 控件的 android:layout_alignParentBottom="true" 實現(xiàn)。

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@+id/tabhost" xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <RelativeLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TabWidget android:id="@android:id/tabs"
      android:layout_width="fill_parent" android:layout_height="wrap_content"
      android:layout_alignParentBottom="true" />
    <FrameLayout android:id="@android:id/tabcontent"
      android:layout_width="fill_parent" android:layout_height="fill_parent">
      <LinearLayout android:id="@+id/tab1"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical">
        <TextView android:id="@+id/view1" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/textView_1" />
      </LinearLayout>
      <LinearLayout android:id="@+id/tab2"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical">
        <TextView android:id="@+id/view2" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/textView_2" />
      </LinearLayout>
      <LinearLayout android:id="@+id/tab3"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical">
        <TextView android:id="@+id/view3" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/textView_3" />
      </LinearLayout>
      <LinearLayout android:id="@+id/tab4"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical">
        <TextView android:id="@+id/view4" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/textView_4" />
      </LinearLayout>
    </FrameLayout>
  </RelativeLayout>
</TabHost>

zhnews.java:

package net.zhnews.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class zhnews extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    setTitle("珠海新聞網Android客戶端");
    TabHost tabs = (TabHost) findViewById(R.id.tabhost);
    tabs.setup();
    TabHost.TabSpec spec = tabs.newTabSpec("tab1");
    spec.setContent(R.id.tab1);
    spec.setIndicator("新聞");
    tabs.addTab(spec);
    spec = tabs.newTabSpec("tab2");
    spec.setContent(R.id.tab2);
    spec.setIndicator("搜聯(lián)社");
    tabs.addTab(spec);
    spec = tabs.newTabSpec("tab3");
    spec.setContent(R.id.tab3);
    spec.setIndicator("影像");
    tabs.addTab(spec);
    spec = tabs.newTabSpec("tab4");
    spec.setContent(R.id.tab4);
    spec.setIndicator("設置");
    tabs.addTab(spec);
    tabs.setCurrentTab(0);
  }
}

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結》、《Android編程之activity操作技巧總結》、《Android操作SQLite數(shù)據庫技巧總結》、《Android操作json格式數(shù)據技巧總結》、《Android數(shù)據庫操作技巧總結》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android資源操作技巧匯總》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

相關文章

最新評論