Android實(shí)現(xiàn)網(wǎng)易新聞客戶端側(cè)滑菜單(1)
Android中很多產(chǎn)品(比如360手機(jī)助手、網(wǎng)易菜單...)都采用側(cè)滑菜單的展現(xiàn)形式,采用這種展現(xiàn)形式
1、能把更多的展現(xiàn)內(nèi)容都存放在菜單中
2、設(shè)計(jì)上也能體現(xiàn)出視覺效果
現(xiàn)在這種交互方式越來越流行了,雖然這種交互方式可以通過自定義組件的方式來實(shí)現(xiàn),但是用三方開源庫更簡單。
SlidingMenu:SlidingMenu的是一種比較新的設(shè)置界面或配置界面效果,在主界面左滑或者右滑出現(xiàn)設(shè)置界面,能方便的進(jìn)行各種操作.目前有大量的應(yīng)用都在使用這一效果。
地址:https://github.com/jfeinstein10/SlidingMenu.git
現(xiàn)在新建一個(gè)Android項(xiàng)目SlidingMenuDemo,
activity_main:
<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" > <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="內(nèi)容" android:textSize="24sp" android:textColor="#000" android:gravity="center" /> </RelativeLayout>
左邊的菜單activity_menu:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="體育" android:textSize="16sp" android:textColor="#000" /> <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="娛樂" android:textSize="16sp" android:textColor="#000" /> <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="財(cái)經(jīng)" android:textSize="16sp" android:textColor="#000" /> <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="科技" android:textSize="16sp" android:textColor="#000" /> <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="杭州" android:textSize="16sp" android:textColor="#000" /> </LinearLayout>
MainActivity.java:
package com.example.slidingmenudemo; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity; import android.os.Bundle; import android.view.Window; import android.app.Activity; public class MainActivity extends SlidingFragmentActivity { private SlidingMenu sm; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); // 1 設(shè)置滑動菜單旁邊的頁面 setBehindContentView(R.layout.activity_menu); setContentView(R.layout.activity_main); //2 獲取滑動菜單 sm = getSlidingMenu(); //3 設(shè)置左滑菜單 sm.setMode(SlidingMenu.LEFT); // 4 設(shè)置滑動菜單出來之后,內(nèi)容頁剩余的寬度 sm.setBehindOffsetRes(R.dimen.slidingmenu_offset); sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); // 6 設(shè)置陰影 sm.setShadowDrawable(R.drawable.shadow); sm.setShadowWidthRes(R.dimen.shadow_width); } }
注意Activity一定要繼承SlidingFragmentActivity。
現(xiàn)在看看SlidingMenu一些屬性:
menu.setMode(SlidingMenu.LEFT);//設(shè)置左滑菜單 menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);//設(shè)置滑動的屏幕范圍,該設(shè)置為全屏區(qū)域都可以滑動 menu.setShadowDrawable(R.drawable.shadow);//設(shè)置陰影圖片 menu.setShadowWidthRes(R.dimen.shadow_width);//設(shè)置陰影圖片的寬度 menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);//SlidingMenu劃出時(shí)主頁面顯示的剩余寬度 menu.setBehindWidth(400);//設(shè)置SlidingMenu菜單的寬度 menu.setFadeDegree(0.35f);//SlidingMenu滑動時(shí)的漸變程度 menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);//使SlidingMenu附加在Activity上 menu.setMenu(R.layout.menu_layout);//設(shè)置menu的布局文件 menu.toggle();//動態(tài)判斷自動關(guān)閉或開啟SlidingMenu menu.showMenu();//顯示SlidingMenu menu.showContent();//顯示內(nèi)容
左右都可以劃出SlidingMenu菜單只需要設(shè)置
menu.setMode(SlidingMenu.LEFT_RIGHT);屬性,然后設(shè)置右側(cè)菜單的布局文件 menu.setSecondaryShadowDrawable(R.drawable.shadowright);//右側(cè)菜單的陰影圖片
設(shè)置SlidingMenu屬性
sm = getSlidingMenu(); //如果只顯示左側(cè)菜單就是用LEFT,右側(cè)就RIGHT,左右都支持就LEFT_RIGHT sm.setMode(SlidingMenu.LEFT_RIGHT);//設(shè)置菜單滑動模式,菜單是出現(xiàn)在左側(cè)還是右側(cè),還是左右兩側(cè)都有 sm.setShadowDrawable(R.drawable.shadow);//設(shè)置陰影的圖片資源 sm.setShadowWidthRes(R.dimen.shadow_width);//設(shè)置陰影圖片的寬度 //sm.setBehindWidth(200);//設(shè)置菜單的寬 sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);//SlidingMenu劃出時(shí)主頁面顯示的剩余寬度 sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);//設(shè)置滑動的區(qū)域
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android項(xiàng)目實(shí)戰(zhàn)之仿網(wǎng)易新聞的頁面(RecyclerView )
- Android實(shí)現(xiàn)仿網(wǎng)易新聞的頂部導(dǎo)航指示器
- Android實(shí)現(xiàn)仿網(wǎng)易新聞主界面設(shè)計(jì)
- Android實(shí)現(xiàn)網(wǎng)易新聞客戶端首頁效果
- Android實(shí)現(xiàn)類似網(wǎng)易新聞選項(xiàng)卡動態(tài)滑動效果
- Android 仿網(wǎng)易新聞客戶端分類排序功能
- Android模擬實(shí)現(xiàn)網(wǎng)易新聞客戶端
- Android組件DrawerLayout仿網(wǎng)易新聞v4.4側(cè)滑菜單
- Android實(shí)現(xiàn)網(wǎng)易新聞客戶端側(cè)滑菜單(2)
- Android仿網(wǎng)易新聞圖片詳情下滑隱藏效果示例代碼
相關(guān)文章
Android開發(fā)必備:秒殺真機(jī)超快模擬器Genymotion介紹
這篇文章主要介紹了Android開發(fā)必備:秒殺真機(jī)超快模擬器Genymotion介紹,本文直接用圖片說明Genymotion的安裝和模擬效果,并提供官網(wǎng),需要的朋友可以參考下2015-04-04Android RecyclerView使用GridLayoutManager間距設(shè)置的方法
本篇文章主要介紹了Android RecyclerView使用GridLayoutManager間距設(shè)置的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12實(shí)現(xiàn)Android 獲取cache緩存的目錄路徑的方法
這篇文章主要介紹了實(shí)現(xiàn)Android 獲取cache緩存的目錄路徑的方法的相關(guān)資料,這里實(shí)現(xiàn)一個(gè)靜態(tài)類來實(shí)現(xiàn)該功能,希望能幫助到大家,需要的朋友可以參考下2017-08-08

Android自定義ViewPager實(shí)現(xiàn)個(gè)性化的圖片切換效果

Android中SurfaceView和普通view的區(qū)別及使用

Android使用Activity實(shí)現(xiàn)簡單的可輸入對話框

android使用 ScrollerView 實(shí)現(xiàn) 可上下滾動的分類欄實(shí)例

Android實(shí)現(xiàn)滑動到頂部懸停的效果