關於使用底部功能表列的使用。。。,使用底部功能表列..

來源:互聯網
上載者:User

關於使用底部功能表列的使用。。。,使用底部功能表列..

要使用它的話, 首先,  你要引用你的庫 到你的當前工程裡面, 操作方式如下,右鍵你當前的工程, build path 下的 Congfig Build Path,進入android,點擊add  然後,就有你的庫的工程,雙擊就ok。

 

 

上面的步驟ok的話,現在就開始使用你的架構了 。  具體

應用的代碼就附在下面吧。

 

package com.example.bluetooth;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Window;
import android.widget.LinearLayout;

import com.weight.tabbottomlib.view.Item;
import com.weight.tabbottomlib.view.MyBottomLayout;
import com.weight.tabbottomlib.view.MyBottomLayout.ICallbackLister;

public class MainActivity extends Activity {
MyBottomLayout bot;
ArrayList<Item> itemData = new ArrayList<Item>();
LinearLayout myContent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
init();
}

/**
* 初始化方法
*/
private void init() {
findId();
initData();
setPageContent(new HomeFragment());
initclick();
}

/**
*
* @Title: setPageContent
* @Description: 設定那個頁面的內容
* @param @param fragment:提交內容的Fragment
* @return
* @throws
*/
public void setPageContent(Fragment fragment) {
FragmentManager manager = getFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.replace(R.id.context, fragment);
ft.commit();
}

/**
* 初始化底部功能表列的資料
*/
private void initData() {
for (int i = 0; i < 3; i++) {
switch (i) {
case 0:
// item.setDrawableNormalId();
Item item = new Item(R.drawable.bottom_fp_nor,
R.drawable.bottom_fp_pre, "首頁");
itemData.add(item);
break;
case 1:
Item item1 = new Item(R.drawable.bottom_ph_nor,
R.drawable.bottom_ph_pre, "陪護師");
itemData.add(item1);
break;
case 2:
Item item2 = new Item(R.drawable.bottom_bbs_nor,
R.drawable.bottom_bbs_pre, "陪護時光");
itemData.add(item2);
break;
}
}
bot.addBottomLayoutValue(itemData);

}

/**
* 找id
*/
private void findId() {
bot = (MyBottomLayout) findViewById(R.id.bottom);
myContent = (LinearLayout) findViewById(R.id.context);
}

/**
* 初始化點擊事件 回調
*/
private void initclick() {
bot.setOnCallbackLister(new ICallbackLister() {

@Override
public void click(int id) {
switch (id) {
case 0:
setPageContent(new HomeFragment());
break;
case 1:
setPageContent(new EscortTeacher());
break;
case 2:
setPageContent(new EscortTime());
break;
}
}
});
}
}

然後你的布局檔案的話 就要寫上你的控制項的包名 + 類名咯。 詳細xml檔案如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<com.weight.tabbottomlib.view.MyBottomLayout
android:id="@+id/bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#9000" >
</com.weight.tabbottomlib.view.MyBottomLayout>

<LinearLayout
android:id="@+id/context"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/bottom"
android:orientation="horizontal" >
</LinearLayout>

</RelativeLayout>

說了這麼多,看看效果吧。

 

 

好了 就看一張效果就好了 ,我個人認為這個很好使用的哦, 底部頁面的切換也都實現了 。 

 還有我是新手,如有說的不對的地方 請大神指教。 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.