DrawerLayout实现网易新闻抽屉效果_第1页
DrawerLayout实现网易新闻抽屉效果_第2页
DrawerLayout实现网易新闻抽屉效果_第3页
DrawerLayout实现网易新闻抽屉效果_第4页
DrawerLayout实现网易新闻抽屉效果_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、个人感觉网易的客户端比拟前卫,有很多新鲜的东西,有时候模仿这些好的客户端 能学到很多东西开始今天的主要课题,下面是网易客户端抽屉模式实现的效果openDrawer(toOpen);break;case LOCK_MODE_LOCKEDCLOSED:final View toClose = findDrawerWithGravity(absGravity);if (toClose != null) closeDrawer(toClose);break;/ default: do nothing)启用或禁用了所有的抽屉互动。其实有个Drawerlayout这个布局,你得问题就已经解决掉一大半了,D

2、rawerlayout布局本身就提供了左划和右划的功能先上代码,然后慢慢解答,看完这篇博客你就知道Drawerlayout怎么用了首先上逐步局文件代码Drawerlayout是Androidv4包里自带的,既然是自带的那么直接拿来用就可以 了,当然前提是你得工程里有v4包下面解释上面的布局文件,让你懂得Drawerlayout用法,首先Drawerlayout支 持左划和右划,那他是如何控制的呢?不居中告诉你,以上布局分为三局部,一般情 况下,第一局部是主步局,第二局部是左划的布局,第三局部是右划的布局,其实这 里的左向滑动和右向滑动是通过gravity控制,左划界面android:layou

3、t_gravity=left当然这里的left也可以用start代替,右划界面 就理所当然的是 android:layout_gravity=rightright 也可以用 end 代替,其余的应该明白了吧!不懂留言,我认真为你解答下面在贴一下主界面的代码,你看懂Drawerlayout用法其余的就很简单了,妈妈 再也不懂担忧你的学习了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);上面主要是监听事件的接口,通常回调的时候回用到它,里面的方法有四个,分别是 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)关闭抽屉onDrawerStateChanged(int newState);改变抽屉的状态/*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();上面这个方法是为了设置用于左或右阴影的简单可拉伸。所提供的可拉伸必须有一个非零固有宽度。public void setScrimColor(int color) mScrimColor = color;invalidate();设置用于该掩盖的主要内容,而抽屉翻开网眼织物的颜色。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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论