版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、個人感覺網(wǎng)易的客戶端比擬前衛(wèi),有很多新鮮的東西,有時候模仿這些好的客戶端 能學(xué)到很多東西開始今天的主要課題,下面是網(wǎng)易客戶端抽屜模式實(shí)現(xiàn)的效果openDrawer(toOpen);break;case LOCK_MODE_LOCKEDCLOSED:final View toClose = findDrawerWithGravity(absGravity);if (toClose != null) closeDrawer(toClose);break;/ default: do nothing)啟用或禁用了所有的抽屜互動。其實(shí)有個Drawerlayout這個布局,你得問題就已經(jīng)解決掉一大半了,D
2、rawerlayout布局本身就提供了左劃和右劃的功能先上代碼,然后慢慢解答,看完這篇博客你就知道Drawerlayout怎么用了首先上逐步局文件代碼Drawerlayout是Androidv4包里自帶的,既然是自帶的那么直接拿來用就可以 了,當(dāng)然前提是你得工程里有v4包下面解釋上面的布局文件,讓你懂得Drawerlayout用法,首先Drawerlayout支 持左劃和右劃,那他是如何控制的呢?不居中告訴你,以上布局分為三局部,一般情 況下,第一局部是主步局,第二局部是左劃的布局,第三局部是右劃的布局,其實(shí)這 里的左向滑動和右向滑動是通過gravity控制,左劃界面android:layou
3、t_gravity=left當(dāng)然這里的left也可以用start代替,右劃界面 就理所當(dāng)然的是 android:layout_gravity=rightright 也可以用 end 代替,其余的應(yīng)該明白了吧!不懂留言,我認(rèn)真為你解答下面在貼一下主界面的代碼,你看懂Drawerlayout用法其余的就很簡單了,媽媽 再也不懂擔(dān)憂你的學(xué)習(xí)了package com. sdufe. thea. guo;import java. util. ArrayList;import java. util. List;import com. sdufe. thea. guo. adapter. ContentAd
4、apter;import com. sdufe. thea. guo. model. ContentModel;import android, os. Bundle;import android, app. Activity;import android, support. v4. widget. DrawerLayout;import android, support. v4. widget. DrawerLayout. DrawerListener;import android, view. Menu;import android, view. MotionEvent;import and
5、roid, view. View;import android, view. View. OnTouchListener;import android, widget. ArrayAdapter;import android, widget. ListView;import android, widget. RelativeLayout;import android, widget. TextView;public class MainActivity extends Activity private DrawerLayout drawerLayout;private RelativeLayo
6、ut leftLayout;private RelativeLayout rightLayout;private List list;private ContentAdapter adapter;Overrideprotected void onCreate(Bundle savedInstanceState) super. onCreate(savedlnstanceState);setContentView(R. layout, activity main);drawerLayout = (DrawerLayout) findViewByld(R. id. drawer1ayou t);l
7、eftLayout=(RelativeLayout) findViewById(R. id. left);rightLayout=(RelativeLayout) findViewById(R. id. right);ListView listView= (ListView) leftLayout. findViewByld(R. id. lef t_listview);initDataO ;adapter=new ContentAdapter (this, list);listView. setAdapter(adapter);private void initDataO list=new
8、ArrayList();list, add (new ContentModel (R. drawable. doctoradvice2, 新I聞);list. add (new ContentModel (R. drawable, infusion selected, 訂I閱 );list, add (new ContentModel (R. drawable. mypatient_selected, 圖 片);list, add (new ContentModel (R. drawable, mywork selected, 視頻 );list, add (new ContentModel
9、(R. drawable. nursingcareplan2, 品艮帖 );list. add (new ContentModel (R. drawable. personal_selected, 投票 );ok,就是這么簡單啦!CSDN 代召馬下載:github 代碼下載: s:/github /zimoguo/DrawerMode源碼首先看Drawerlayout,他繼承自ViewGroup,這里主要看一下它里面的方法,方便以后使用/* Listener for monitoring events about drawers.*/public interface DrawerListene
10、r /*Called when a drawers position changes.param drawerView The child view that was movedparam slideOffset The new offset of this drawer within its range, f rom 0-1*/public void onDrawerSlide(View drawerView, float slideOffset);/*Called when a drawer has settled in a completely open state.The drawer
11、 is interactive at this point.*param drawerView Drawer view that is now open*/public void onDrawerOpened(View drawerView);/*Called when a drawer has settled in a completely closed state.*param drawerView Drawer view that is now closed*/public void onDrawerClosed(View drawerView);/*Called when the dr
12、awer motion state changes. The new state willbe one of link #STATE_IDLE, link #STATE_DRAGGING or link #ST ATE_SETTLING.*param newState The new drawer motion state*/public void onDrawerStateChanged(int newState);上面主要是監(jiān)聽事件的接口,通常回調(diào)的時候回用到它,里面的方法有四個,分別是 onDrawerSlide(View drawerView, floatslideOffset);on
13、DrawerOpened(View drawerView);onDrawerClosed(ViewdrawerView);onDrawerStateChanged(int newState);onDrawerSlide(View drawerView, float slideOffset)抽屜改變時使用onDrawerOpened(View drawerView)才了開抽屜onDrawerClosed(View drawerView)關(guān)閉抽屜onDrawerStateChanged(int newState);改變抽屜的狀態(tài)/*Set a simple drawable used for th
14、e left or right shadow.The drawable provided must have a nonzero intrinsic width.*param shadowDrawable Shadow drawable to use at the edge of a drawerparam gravity Which drawer the shadow should apply to/public void setDrawerShadow(Drawable shadowDrawable, int gravity) /*TODO Someone someday might wa
15、nt to set more complex drawables here.They,re probably nuts, but we might want to consider registering cal Ibacks,setting states, etc. properly./final int absGravity = GravityCompat. getAbsoluteGravity(gravity,ViewCompat. getLayoutDirection(this);if (absGravity & Gravity. LEFT) = Gravity. LEFT) mSha
16、dowLeft = shadowDrawable;invalidate();)if (absGravity & Gravity. RIGHT) = Gravity. RIGHT) mShadowRight = shadowDrawable;invalidate();上面這個方法是為了設(shè)置用于左或右陰影的簡單可拉伸。所提供的可拉伸必須有一個非零固有寬度。public void setScrimColor(int color) mScrimColor = color;invalidate();設(shè)置用于該掩蓋的主要內(nèi)容,而抽屜翻開網(wǎng)眼織物的顏色。public void setDrawerLockMode(int lockMode, int edgeGravity) final int absGravity = GravityCompat. getAbsoluteGravity(edgeGravity, ViewCompat. getLayoutDirection(this);if (absGravity = Gravity. LEFT) mLockModeLeft = lockMode; else if (absGravity = Gravity. RIGHT) mLockModeRight = lockMode;if (lockMode != L0CK_M0DE_UN
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 單位管理制度呈現(xiàn)大全【職員管理】十篇
- 《客房清掃程序》課件
- 《番茄晚疫病》課件
- 《四年級下語文總結(jié)》與《四年級本學(xué)期的總結(jié)》與《四年級本學(xué)期的總結(jié)反思》范文匯編
- 復(fù)習(xí)培優(yōu)卷03 第5單元(解析版)
- 第5單元+國防建設(shè)與外交成就
- 軟件開發(fā)委托合同三篇
- 農(nóng)業(yè)投資盈利之路
- 設(shè)計裝修銷售工作總結(jié)
- 游戲行業(yè)前臺工作總結(jié)
- MOOC 社會保障學(xué)-江西財經(jīng)大學(xué) 中國大學(xué)慕課答案
- MOOC 理論力學(xué)-國防科技大學(xué) 中國大學(xué)慕課答案
- 城市規(guī)劃設(shè)計計費(fèi)指導(dǎo)意見(2004年)
- 制造業(yè)成本精細(xì)化管理
- 工業(yè)互聯(lián)網(wǎng)標(biāo)準(zhǔn)體系(版本3.0)
- 初中生物老師經(jīng)驗(yàn)交流課件
- 柴油發(fā)電機(jī)組采購施工 投標(biāo)方案(技術(shù)方案)
- 股權(quán)招募計劃書
- 創(chuàng)業(yè)之星學(xué)創(chuàng)杯經(jīng)營決策常見問題匯總
- 公豬站工作總結(jié)匯報
- 醫(yī)學(xué)專業(yè)醫(yī)學(xué)統(tǒng)計學(xué)試題(答案見標(biāo)注) (三)
評論
0/150
提交評論