SlidingMenu 側滑的開源專案

2021-12-29 21:25:08 字數 2149 閱讀 8979

slidingmenu是乙個側滑的開源專案需要應用第三方包。

其主要實現的步驟有:

1. 設定側滑layout

2. 設定側滑屬性

3. 側滑view關聯到activity上容 如果是直接使用slidingmenuactivity就不需要關聯。

實現的方式:

1. 在activity中直接使用,如下步驟:

`slidingmenu menu = new slidingmenu(this);

menu.setmode(slidingmenu.left);

// 設定觸控螢幕的模式

menu.settouchmodeabove(slidingmenu.touchmode_fullscreen);

menu.setshadowwidthres(r.dimen.shadow_width);

menu.setshadowdrawable(r.drawable.shadow);

// 設定滑動選單檢視的寬度

menu.setbehindoffsetres(r.dimen.slidingmenu_offset);

// 設定漸入漸出效果的值

menu.setfadedegree(0.35f);

/**

* sliding_window will include the title/actionbar in the content

* section of the slidingmenu, while sliding_content does not.

*/

menu.attachtoactivity(this, slidingmenu.sliding_content);

//為側滑選單設定布局

menu.setmenu(r.layout.leftmenu);`

2.把slidingmenu當作普通的控制項使用。

3.使用在fragment中使用,當作乙個view來使用,與第一種方式相似,**有細微的差異,如下:

「`fragment leftmenufragment = new menuleftfragment();

setbehindcontentview(r.layout.left_menu_frame);

getsupportfragmentmanager().begintransaction()

.replace(r.id.id_left_menu_frame, leftmenufragment).commit();

slidingmenu menu = getslidingmenu();

menu.setmode(slidingmenu.left_right);

// 設定觸控螢幕的模式

menu.settouchmodeabove(slidingmenu.touchmode_margin);

menu.setshadowwidthres(r.dimen.shadow_width);

menu.setshadowdrawable(r.drawable.shadow);

// 設定滑動選單檢視的寬度

menu.setbehindoffsetres(r.dimen.slidingmenu_offset);

// 設定漸入漸出效果的值

menu.setfadedegree(0.35f);

// menu.setbehindscrollscale(1.0f);

menu.setsecondaryshadowdrawable(r.drawable.shadow);

//設定右邊(二級)側滑選單

menu.setsecondarymenu(r.layout.right_menu_frame);

fragment rightmenufragment = new menurightfragment();

getsupportfragmentmanager().begintransaction()

.replace(r.id.id_right_menu_frame, rightmenufragment).commit();注意點:setbehindcontentview要最先的調傭,否則會錯誤

SlidingMenu 簡單側滑

slidingmenu menu new slidingmenu this menu.setmode slidingmenu.left 設定側滑 左滑 還是右滑 menu.settouchmodeabove slidingmenu.sliding window 設定觸控螢幕的模式 menu.setb...

SlidingMenu側滑簡單實現

建立乙個空的xml布局檔案,布局裡用framelayout給framelayout乙個id id是 紅色字型部分 新增空的布局是黃色字型部分 framelayoutxmlns android android id id menu frame android layout width match pa...

SlidingMenu實現 app側滑功能

側拉 final slidingmenu menu new slidingmenu this menu.setmode slidingmenu.left 設定選單滑動模式,選單是出現在左側 left right左右兩側都有 right右側 menu.settouchmodeabove sliding...