編輯:關於Android編程
本文實例講述了Android簡單實現屏幕下方Tab菜單的方法。分享給大家供大家參考,具體如下:
看到很多熱門的Android程序(如:新浪微博、騰訊微博、京東商城、淘寶、當當等等)使用選項卡風格作為程序界面的主框架結構,而Android的選項卡控件默認是按鈕在上方的。我在網上看到有多種實現方法,這裡提供一種個人覺得比較簡單的。由於我對Android開發所知甚少,方法的優劣目前不好評價,歡迎各位提供更好的思路。
主要原理:設置 TabWidget 控件的 android:layout_alignParentBottom="true" 實現。
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("搜聯社");
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開發入門與進階教程》、《Android視圖View技巧總結》、《Android編程之activity操作技巧總結》、《Android操作SQLite數據庫技巧總結》、《Android操作json格式數據技巧總結》、《Android數據庫操作技巧總結》、《Android文件操作技巧匯總》、《Android編程開發之SD卡操作方法匯總》、《Android資源操作技巧匯總》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
Android跳轉到通訊錄獲取用戶名稱和手機號碼的實現思路
效果圖如下所示:先給大家說下實現android 跳轉到通訊錄的實現思路:1.點擊跳轉到通訊錄界面2.獲取通訊錄姓名和手機號碼3.回調顯示姓名和手機號碼1首先是跳轉到通訊錄
Android滑動組件懸浮固定在頂部效果
要想實現的效果是如下:場景:有些時候是內容中間的組件當滑動至頂部的時候固定顯示在頂部。實現的思路:1.目標組件(button)有兩套,放在頂部和內容中間;2.當內容中間的
Android--藍牙操作(藍牙的打開與關閉,可見性的打開與關閉)
BluetoothAdapter 用法藍牙運行原理:通過BluetoothAdapter 藍牙適配器處理任務,如果藍牙被啟動之後,系統會自動去搜索其它
Android開發高仿課程表的布局實例詳解
先說下這個demo,這是一個模仿課程表的布局文件,雖然我是個菜鳥,但我還是想留給學習的人一些例子,先看下效果 然後再來看一下我們學校的app布局分析先上一張劃分