IPv6互联网 思维具有 优势哪些优势?

android-undergarment 是 Android 上实现滑盖导航(抽屉)效果的 UI 组件。
集成这个组件非常简单 ,只要在activity的oncreate中加入:
mDrawerGarment = new DrawerGarment(this, R.layout.dashboard);
mDrawerGarment = new DrawerGarment(this, R.layout.dashboard);
资源整理者简介:
可能感兴趣的文章
怎么实现、
按分类快速查找
关于资源导航
伯乐在线资源导航收录优秀的工具资源。内容覆盖开发、设计、产品和管理等IT互联网行业相关的领域。目前已经收录 1438 项工具资源。
关于资源导航
伯乐在线资源导航收录优秀的工具资源。内容覆盖开发、设计、产品和管理等IT互联网行业相关的领域。
新浪微博:
推荐微信号
(加好友请注明来意)
- 好的话题、有启发的回复、值得信赖的圈子
- 分享和发现有价值的内容与观点
- 为IT单身男女服务的征婚传播平台
- 优秀的工具资源导航
- 翻译传播优秀的外文文章
- 国内外的精选博客文章
- UI,网页,交互和用户体验
- 专注iOS技术分享
- 专注Android技术分享
- JavaScript, HTML5, CSS
- 专注Java技术分享
- 专注Python技术分享
& 2017 伯乐在线&>&&>&&>&&>&android抽屉效果实现
android抽屉效果实现
上传大小:85KB
* 功能一、屏幕分上下二部分;通过打开按钮实现,抽屉的下面部分打开和关闭,同时上面部分自动伸展。
* 功能二、点击黑色部分能够实现拖拉,
综合评分:5(1位用户评分)
所需积分:5
下载次数:5
审核通过送C币
创建者:otldan
创建者:huang3513
创建者:xiaoyaoyou1212
课程推荐相关知识库
上传者其他资源上传者专辑
移动开发热门标签
VIP会员动态
android服务器底层网络模块的设计方法
所需积分:0
剩余积分:720
您当前C币:0
可兑换下载积分:0
兑换下载分:
兑换失败,您当前C币不够,请先充值C币
消耗C币:0
你当前的下载分为234。
android抽屉效果实现
会员到期时间:
剩余下载次数:
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:android怎么实现类似抽屉效果(如图)
大家应该懂的吧..
平移动画......
--- 共有 1 条评论 ---
但是我希望他的收缩过程中下面的会上移,也就是说.平移时,实际的layout_height也变小.莫非我自己写个线程改变layout_height算了?
网上抽屉效果例子很多的,只需要你自己再根据自己需要稍微改进一下就好了,看着你的好像不是全部推拉的,是局部收缩吗?是的话你就写一个点击事件了,点击以后对你想收缩的部分做 隐藏,或删除 &就看自己的需求了
--- 共有 1 条评论 ---
这样就没有动画效果了,我需要点击后.(像官方提供的SlidingDraw控件一样,官方也说明了,最好自己根据SlidingDraw自己实现)下面的部分会上移,红框内的部分收缩.
如果你拉出来的界面比较复杂的话。你可以通过ScrollView或者HorizontalScrollView来实现,会很方便!
如果单单用平移动画做,比较麻烦。
&&&&1. 触发按钮和拉出界面分开设计,分别启动动画会出现间隔。
& & 2. 如果一起设计,那你view的坐标又不好控制。
所以我推荐你用ScrollView。由三部分组成,上方的透明部分,中间的响应按钮,以及下面的拉出界面。
& & 当出发响应按钮,则通过setSelection(int)或setSelectionFrom(int, int)来实现。
--- 共有 4 条评论 ---
: 求code,我的邮箱是 ~
ScrollView中 我上面说的是从下拉出来ScrollView子view的顺序,反过来不就可以适应你的了么。
: 你可以看一下SlideDraw的源码。我记得里面也是用ScrollView实现的。
就是滚动啊,点击handle滚出来,在点滚回去。so easy.
如果需要我可以吧code给你。
上面红框是拉出部分,我比较想实现像slidingDraw那样,但它那个位置和方向都定死了.额,ScrollView不是一个滚动的吗?
简单点的话就直接使用动画吧
--- 共有 1 条评论 ---
能说这样的话的人一点都不简单啊
引用来自“打杂程序猿”的答案平移动画......组合动画...
引用来自“刎枫”的答案 如果你拉出来的界面比较复杂的话。你可以通过ScrollView或者HorizontalScrollView来实现,会很方便!
如果单单用平移动画做,比较麻烦。
&&&&1. 触发按钮和拉出界面分开设计,分别启动动画会出现间隔。
& & 2. 如果一起设计,那你view的坐标又不好控制。
所以我推荐你用ScrollView。由三部分组成,上方的透明部分,中间的响应按钮,以及下面的拉出界面。
& & 当出发响应按钮,则通过setSelection(int)或setSelectionFrom(int, int)来实现。Android实现自定义滑动式抽屉效果菜单
投稿:lijiao
字体:[ ] 类型:转载 时间:
这篇文章主要为大家详细介绍了Android实现自定义滑动式抽屉效果菜单,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
在Andoird使用Android自带的那些组件,像SlidingDrawer和DrawerLayout都是抽屉效果的菜单,但是在项目很多要实现的功能都收到Android这些自带组件的限制,导致很难完成项目的需求,自定义的组件,各方面都在自己的控制之下,从而根据需求做出调整。想要实现好的效果,基本上都的基于Android的OnTouch事件自己实现响应的功能。
首先,给大家先看一下整体的效果:
滑动的加速度效果都是有的,具体的体验,只能安装后才能查看。
接下来,看代码:
代码从MainActivity延伸出了2个类:MainController和MainView,MainController来处理控制层、MainView来操作展示层。
主要代码:
MainActivity的代码:
package com.example.
import com.example.wz.controller.MainC
import com.example.wz.util.MyL
import com.example.wz.view.MainV
import android.app.A
import android.os.B
import android.view.MotionE
public class MainActivity extends Activity {
public MyLog log = new MyLog(this, true);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
log.e("欢迎你加入测试项目.");
public MainController mainC
public MainView mainV
private void link() {
this.mainController = new MainController(this);
this.mainView = new MainView(this);
this.mainController.thisView = this.mainV
this.mainView.thisController = this.mainC
this.mainView.initViews();
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
return mainController.onTouchEvent(event);
MainController的代码:
package com.example.wz.
import android.view.GestureD
import android.view.GestureDetector.SimpleOnGestureL
import android.view.MotionE
import com.example.wz.MainA
import com.example.wz.util.MyL
import com.example.wz.util.OpenL
import com.example.wz.util.OpenLooper.LoopC
import com.example.wz.view.MainV
public class MainController {
public MyLog log = new MyLog(this, true);
public MainActivity mainA
public MainController thisC
public MainView thisV
public GestureDetector mG
public MainController(MainActivity mainActivity) {
this.mainActivity = mainA
this.thisController =
mGesture = new GestureDetector(mainActivity, new GestureListener());
openLooper = new OpenLooper();
openLooper.createOpenLooper();
loopCallback = new ListLoopCallback(openLooper);
openLooper.loopCallback = loopC
public class TouchStatus {
public int None = 4, Down = 1, Horizontal = 2, Vertical = 3, Up = 4;// LongPress = 5
public int state = N
public TouchStatus touchStatus = new TouchStatus();
public class BodyStatus {
public int Fixed = 0, Dragging = 1, Homing = 2, FlingHoming = 3, BoundaryHoming = 4;
public int state = F
public BodyStatus bodyStatus = new BodyStatus();
public class DrawStatus {
public int Closed = 0, Open = 1, GoClosing = 2, GoOpening = 3;
public int state = C
public DrawStatus drawStatus = new DrawStatus();
public class AreaStatus {
public int A = 0, B = 1;
public int state = A;
public AreaStatus areaStatus = new AreaStatus();
public float touch_pre_x;
public float touch_pre_y;
public float currentTranslateX;
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
float x = event.getX();
float y = event.getY();
if (action == MotionEvent.ACTION_DOWN) {
this.touch_pre_x =
this.touch_pre_y =
if (touchStatus.state == touchStatus.None) {
touchStatus.state = touchStatus.D
log.e("Down ");
if (x & thisView.maxTranslateX) {
areaStatus.state = areaStatus.B;
} else if (x &= thisView.maxTranslateX) {
areaStatus.state = areaStatus.A;
} else if (action == MotionEvent.ACTION_MOVE) {
float Δy = (y - touch_pre_y);
float Δx = (x - touch_pre_x);
if (touchStatus.state == touchStatus.Down) {
if (Δx * Δx + Δy * Δy & 400) {
if (Δx * Δx & Δy * Δy) {
touchStatus.state = touchStatus.H
touchStatus.state = touchStatus.V
touch_pre_x =
touch_pre_y =
log.e("ACTION_MOVE ");
} else if (touchStatus.state == touchStatus.Horizontal) {
currentTranslateX += Δx;
this.touch_pre_x =
this.touch_pre_y =
if (currentTranslateX - thisView.maxTranslateX &= 0 && currentTranslateX &= 0) {
setPosition();
log.e("Horizontal");
bodyStatus.state = bodyStatus.D
} else if (touchStatus.state == touchStatus.Vertical) {
log.e("Vertical");
bodyStatus.state = bodyStatus.D
} else if (action == MotionEvent.ACTION_UP) {
log.e("ACTION_UP");
if (bodyStatus.state == bodyStatus.Dragging) {
if (touchStatus.state == touchStatus.Horizontal) {
bodyStatus.state = bodyStatus.H
openLooper.start();
} else if (touchStatus.state == touchStatus.Vertical) {
if (drawStatus.state == drawStatus.Open && areaStatus.state == areaStatus.B) {
bodyStatus.state = bodyStatus.H
drawStatus.state = drawStatus.GoC
openLooper.start();
} else if (touchStatus.state == touchStatus.Down && areaStatus.state == areaStatus.B) {
bodyStatus.state = bodyStatus.H
drawStatus.state = drawStatus.GoC
openLooper.start();
touchStatus.state = touchStatus.Up;
mGesture.onTouchEvent(event);
class GestureListener extends SimpleOnGestureListener {
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (velocityX * velocityX + velocityY * velocityY & 250000) {
if (velocityX * velocityX & velocityY * velocityY) {
log.e("velocityX--" + velocityX);
if (drawStatus.state == drawStatus.Closed && velocityX & 0) {
} else if (drawStatus.state == drawStatus.Open && velocityX & 0) {
dxSpeed = velocityX;
bodyStatus.state = bodyStatus.FlingH
openLooper.start();
log.e("velocityY");
public void onLongPress(MotionEvent event) {
public boolean onDoubleTap(MotionEvent event) {
public boolean onDoubleTapEvent(MotionEvent event) {
public boolean onSingleTapUp(MotionEvent event) {
public boolean onSingleTapConfirmed(MotionEvent event) {
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
public void setPosition() {
thisView.v1.setTranslationX(currentTranslateX - thisView.maxTranslateX);
thisView.v2.setTranslationX(Math.abs(currentTranslateX));
float transleteSpeed = 3f;
OpenLooper openLooper =
LoopCallback loopCallback =
public class ListLoopCallback extends LoopCallback {
public ListLoopCallback(OpenLooper openLooper) {
openLooper.super();
public void loop(double ellapsedMillis) {
if (bodyStatus.state == bodyStatus.Homing) {
hommingView((float) ellapsedMillis);
} else if (bodyStatus.state == bodyStatus.FlingHoming) {
flingHomingView((float) ellapsedMillis);
public float ratio = 0.0008f;
public void flingHomingView(float ellapsedMillis) {
float distance = (float) ellapsedMillis * transleteS
boolean isStop =
if (drawStatus.state == drawStatus.Closed) {
drawStatus.state = drawStatus.GoO
} else if (drawStatus.state == drawStatus.Open) {
drawStatus.state = drawStatus.GoC
if (drawStatus.state == drawStatus.GoClosing) {
this.currentTranslateX -=
if (this.currentTranslateX &= 0) {
this.currentTranslateX = 0;
drawStatus.state = drawStatus.C
log.e("-------------1");
} else if (drawStatus.state == drawStatus.GoOpening) {
this.currentTranslateX +=
if (this.currentTranslateX &= thisView.maxTranslateX) {
this.currentTranslateX = thisView.maxTranslateX;
drawStatus.state = drawStatus.O
log.e("-------------2");
setPosition();
if (isStop) {
openLooper.stop();
public float dxS
public void dampenSpeed(long deltaMillis) {
if (this.dxSpeed != 0.0f) {
this.dxSpeed *= (1.0f - 0.002f * deltaMillis);
if (Math.abs(this.dxSpeed) & 50f)
this.dxSpeed = 0.0f;
public void hommingView(float ellapsedMillis) {
float distance = (float) ellapsedMillis * transleteS
boolean isStop =
if (drawStatus.state == drawStatus.Closed && this.currentTranslateX & thisView.maxTranslateX / 5) {
this.currentTranslateX -=
if (this.currentTranslateX &= 0) {
this.currentTranslateX = 0;
drawStatus.state = drawStatus.C
} else if (drawStatus.state == drawStatus.Closed && this.currentTranslateX &= thisView.maxTranslateX / 5) {
this.currentTranslateX +=
if (this.currentTranslateX &= thisView.maxTranslateX) {
this.currentTranslateX = thisView.maxTranslateX;
drawStatus.state = drawStatus.O
} else if (drawStatus.state == drawStatus.Open && this.currentTranslateX & thisView.maxTranslateX / 5 * 4) {
this.currentTranslateX -=
if (this.currentTranslateX &= 0) {
this.currentTranslateX = 0;
drawStatus.state = drawStatus.C
} else if (drawStatus.state == drawStatus.Open && this.currentTranslateX &= thisView.maxTranslateX / 5 * 4) {
this.currentTranslateX +=
if (this.currentTranslateX &= thisView.maxTranslateX) {
this.currentTranslateX = thisView.maxTranslateX;
drawStatus.state = drawStatus.O
} else if (drawStatus.state == drawStatus.GoClosing) {
this.currentTranslateX -=
if (this.currentTranslateX &= 0) {
this.currentTranslateX = 0;
drawStatus.state = drawStatus.C
setPosition();
if (isStop) {
openLooper.stop();
log.e("looper stop...");
MainView的代码:
package com.example.wz.
import android.graphics.C
import android.util.DisplayM
import android.view.ViewGroup.LayoutP
import android.widget.RelativeL
import android.widget.TextV
import com.example.wz.MainA
import com.example.wz.R;
import com.example.wz.controller.MainC
import com.example.wz.util.MyL
public class MainView {
public MyLog log = new MyLog(this, true);
public MainActivity mainA
public MainController thisC
public MainView thisV
public MainView(MainActivity mainActivity) {
this.mainActivity = mainA
this.thisView =
public DisplayMetrics displayM
public float screenW
public float screenH
public float maxTranslateX;
public RelativeLayout maxV
public RelativeLayout v1;
public RelativeLayout v2;
public void initViews() {
this.displayMetrics = new DisplayMetrics();
this.mainActivity.getWindowManager().getDefaultDisplay().getMetrics(this.displayMetrics);
this.screenHeight = this.displayMetrics.heightP
this.screenWidth = this.displayMetrics.widthP
this.density = this.displayMetrics.
this.maxTranslateX = this.screenWidth * 0.8f;
this.mainActivity.setContentView(R.layout.activity_main);
this.maxView = (RelativeLayout) this.mainActivity.findViewById(R.id.maxView);
v1 = new RelativeLayout(mainActivity);
v1.setBackgroundColor(Color.RED);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams((int) this.maxTranslateX, LayoutParams.MATCH_PARENT);
this.maxView.addView(v1, params1);
TextView t1 = new TextView(mainActivity);
t1.setText("left menu bar");
t1.setTextColor(Color.WHITE);
v1.addView(t1);
v1.setTranslationX(0 - this.maxTranslateX);
v2 = new RelativeLayout(mainActivity);
v2.setBackgroundColor(Color.parseColor("#0099cd"));
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams((int) this.screenWidth, LayoutParams.MATCH_PARENT);
this.maxView.addView(v2, params2);
v2.setTranslationX(0);
TextView t2 = new TextView(mainActivity);
t2.setText("body content");
t2.setTextColor(Color.WHITE);
v2.addView(t2);
日志管理类MyLog:
package com.example.wz.
import android.util.L
public class MyLog {
public static boolean isGlobalTurnOn =
public boolean isTurnOn =
public String tag =
public MyLog(String tag, boolean isTurnOn) {
this.tag =
this.isTurnOn = isTurnOn;
public MyLog(Object clazz, boolean isTurnOn) {
this.tag = clazz.getClass().getSimpleName();
this.isTurnOn = isTurnOn;
public void v(String message) {
this.v(this.tag, message);
public void d(String message) {
this.d(this.tag, message);
public void i(String message) {
this.i(this.tag, message);
public void w(String message) {
this.w(this.tag, message);
public void e(String message) {
this.e(this.tag, message);
public void v(String tag, String message) {
if (isTurnOn && isGlobalTurnOn) {
Log.v(tag, message);
public void d(String tag, String message) {
if (isTurnOn && isGlobalTurnOn) {
Log.d(tag, message);
public void i(String tag, String message) {
if (isTurnOn && isGlobalTurnOn) {
Log.i(tag, message);
public void w(String tag, String message) {
if (isTurnOn && isGlobalTurnOn) {
Log.w(tag, message);
public void e(String tag, String message) {
if (isTurnOn && isGlobalTurnOn) {
Log.e(tag, message);
实现动画效果的核心类OpenLooper:
package com.example.wz.
import android.annotation.TargetA
import android.os.B
import android.os.H
import android.os.SystemC
import android.view.C
public class OpenLooper {
public LegacyAndroidSpringLooper legacyAndroidSpringLooper =
public ChoreographerAndroidSpringLooper choreographerAndroidSpringLooper =
public LoopCallback loopCallback =
public void createOpenLooper() {
if (Build.VERSION.SDK_INT &= Build.VERSION_CODES.JELLY_BEAN) {
choreographerAndroidSpringLooper = new ChoreographerAndroidSpringLooper();
legacyAndroidSpringLooper = new LegacyAndroidSpringLooper();
public void start() {
if (choreographerAndroidSpringLooper != null) {
choreographerAndroidSpringLooper.start();
} else if (legacyAndroidSpringLooper != null) {
legacyAndroidSpringLooper.start();
public void stop() {
if (choreographerAndroidSpringLooper != null) {
choreographerAndroidSpringLooper.stop();
} else if (legacyAndroidSpringLooper != null) {
legacyAndroidSpringLooper.stop();
public class LoopCallback {
public void loop(double ellapsedMillis) {
public void loop(double ellapsedMillis) {
if (this.loopCallback != null) {
this.loopCallback.loop(ellapsedMillis);
public class LegacyAndroidSpringLooper {
public Handler mH
public Runnable mLooperR
public boolean mS
public long mLastT
public LegacyAndroidSpringLooper() {
initialize(new Handler());
public void initialize(Handler handler) {
mHandler =
mLooperRunnable = new Runnable() {
public void run() {
if (!mStarted) {
long currentTime = SystemClock.uptimeMillis();
loop(currentTime - mLastTime);
mHandler.post(mLooperRunnable);
public void start() {
if (mStarted) {
mStarted =
mLastTime = SystemClock.uptimeMillis();
mHandler.removeCallbacks(mLooperRunnable);
mHandler.post(mLooperRunnable);
public void stop() {
mStarted =
mHandler.removeCallbacks(mLooperRunnable);
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class ChoreographerAndroidSpringLooper {
public Choreographer mC
public Choreographer.FrameCallback mFrameC
public boolean mS
public long mLastT
public ChoreographerAndroidSpringLooper() {
initialize(Choreographer.getInstance());
public void initialize(Choreographer choreographer) {
mChoreographer =
mFrameCallback = new Choreographer.FrameCallback() {
public void doFrame(long frameTimeNanos) {
if (!mStarted) {
long currentTime = SystemClock.uptimeMillis();
loop(currentTime - mLastTime);
mLastTime = currentT
mChoreographer.postFrameCallback(mFrameCallback);
public void start() {
if (mStarted) {
mStarted =
mLastTime = SystemClock.uptimeMillis();
mChoreographer.removeFrameCallback(mFrameCallback);
mChoreographer.postFrameCallback(mFrameCallback);
public void stop() {
mStarted =
mChoreographer.removeFrameCallback(mFrameCallback);
转载来自:
源码下载:
以上就是本文的全部内容,希望对大家的学习有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具Android 使用Drawerlayout仿网易新闻客户端抽屉模式
61709次浏览
个人感觉网易的客户端比较前卫,有很多新鲜的东西,有时候模仿这些好的客户端能学到很多东西
开始今天的主要课题,下面是网易客户端抽屉模式实现的效果
其实有个Drawerlayout这个布局,你得问题就已经解决掉一大半了,Drawerlayout布局本身就提供了左划和右划的功能
先上代码,然后慢慢解答,看完这篇博客你就知道Drawerlayout怎么用了
首先上逐步局文件代码
&android.support.v4.widget.DrawerLayout xmlns:android=&/apk/res/android&
xmlns:tools=&/tools&
android:id=&@+id/drawerlayout&
android:layout_width=&match_parent&
android:layout_height=&match_parent& &
&FrameLayout
android:id=&@+id/fragment_layout&
android:layout_width=&match_parent&
android:layout_height=&match_parent& &
&/FrameLayout&
&RelativeLayout
android:id=&@+id/left&
android:layout_width=&200dp&
android:layout_height=&match_parent&
android:layout_gravity=&left&
android:background=&@android:color/white&&
android:id=&@+id/left_listview&
android:layout_width=&match_parent&
android:layout_height=&match_parent& &
&/ListView&
&/RelativeLayout&
&RelativeLayout
android:id=&@+id/right&
android:layout_width=&260dp&
android:layout_height=&match_parent&
android:layout_gravity=&right&
android:background=&@android:color/holo_green_light&&
android:id=&@+id/right_textview&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:text=&个人登陆页面& /&
&/RelativeLayout&
&/android.support.v4.widget.DrawerLayout&
Drawerlayout是Androidv4包里自带的,既然是自带的那么直接拿来用就可以了,当然前提是你得工程里有v4包
下面解释上面的布局文件,让你懂得Drawerlayout用法,首先Drawerlayout支持左划和右划,那他是如何控制的呢?不居中告诉你,以上布局分为三部分,一般情况下,第一部分是主步局,第二部分是左划的布局,第三部分是右划的布局,其实这里的左向滑动和右向滑动是通过gravity控制,左划界面android:layout_gravity=&left& 当然这里的left也可以用start代替,右划界面就理所当然的是android:layout_gravity=&right& ,同样right也可以用end代替,其余的应该明白了吧!不懂留言,我认真为你解答
下面在贴一下主界面的代码,你看懂Drawerlayout用法其余的就很简单了,妈妈再也不懂担心你的学习了
package com.sdufe.thea.
import java.util.ArrayL
import java.util.L
import com.sdufe.thea.guo.adapter.ContentA
import com.sdufe.thea.guo.model.ContentM
import android.os.B
import android.app.A
import android.support.v4.widget.DrawerL
import android.support.v4.widget.DrawerLayout.DrawerL
import android.view.M
import android.view.MotionE
import android.view.V
import android.view.View.OnTouchL
import android.widget.ArrayA
import android.widget.ListV
import android.widget.RelativeL
import android.widget.TextV
public class MainActivity extends Activity {
private DrawerLayout drawerL
private RelativeLayout leftL
private RelativeLayout rightL
private List&ContentModel&
private ContentA
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerLayout = (DrawerLayout) findViewById(R.id.drawerlayout);
leftLayout=(RelativeLayout) findViewById(R.id.left);
rightLayout=(RelativeLayout) findViewById(R.id.right);
ListView listView=(ListView) leftLayout.findViewById(R.id.left_listview);
initData();
adapter=new ContentAdapter(this, list);
listView.setAdapter(adapter);
private void initData() {
list=new ArrayList&ContentModel&();
list.add(new ContentModel(R.drawable.doctoradvice2, &新闻&));
list.add(new ContentModel(R.drawable.infusion_selected, &订阅&));
list.add(new ContentModel(R.drawable.mypatient_selected, &图片&));
list.add(new ContentModel(R.drawable.mywork_selected, &视频&));
list.add(new ContentModel(R.drawable.nursingcareplan2, &跟帖&));
list.add(new ContentModel(R.drawable.personal_selected, &投票&));
ok,就是这么简单啦!
CSDN代码下载:http://download.csdn.net/detail/elinavampire/8195349
github代码下载:/zimoguo/DrawerMode
................................................源码.....................................................................
首先看Drawerlayout,他继承自ViewGroup,这里主要看一下它里面的方法,方便以后使用
* Listener for monitoring events about drawers.
public interface DrawerListener {
* Called when a drawer's position changes.
* @param drawerView The child view that was moved
* @param slideOffset The new offset of this drawer within its range, from 0-1
public void onDrawerSlide(View drawerView, float slideOffset);
* Called when a drawer has settled in a completely open state.
* The drawer 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 drawer motion state changes. The new state will
* be one of {@link #STATE_IDLE}, {@link #STATE_DRAGGING} or {@link #STATE_SETTLING}.
* @param newState The new drawer motion state
public void onDrawerStateChanged(int newState);
上面主要是监听事件的接口,通常回调的时候回用到它,里面的方法有四个,分别是onDrawerSlide(View drawerView, float slideOffset);onDrawerOpened(View drawerView);onDrawerClosed(View drawerView);onDrawerStateChanged(int newState);
onDrawerSlide(View drawerView, float slideOffset)抽屉改变时使用
onDrawerOpened(View drawerView);打开抽屉
onDrawerClosed(View drawerView)关闭抽屉
onDrawerStateChanged(int newState);改变抽屉的状态
* Set a simple drawable used for the left or right shadow.
* The drawable provided must have a nonzero intrinsic width.
* @param shadowDrawable Shadow drawable to use at the edge of a drawer
* @param gravity Which drawer the shadow should apply to
public void setDrawerShadow(Drawable shadowDrawable, int gravity) {
* TODO Someone someday might want to set more complex drawables here.
* They're probably nuts, but we might want to consider registering callbacks,
* setting states, etc. properly.
final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
ViewCompat.getLayoutDirection(this));
if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
mShadowLeft = shadowD
invalidate();
if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
mShadowRight = shadowD
invalidate();
上面这个方法是为了设置用于左或右阴影的简单可拉伸。所提供的可拉伸必须有一个非零固有宽度。
public void setScrimColor(int color) {
mScrimColor =
invalidate();
设置用于该掩盖的主要内容,而抽屉打开网眼织物的颜色。
public void setDrawerLockMode(int lockMode, int edgeGravity) {
final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity,
ViewCompat.getLayoutDirection(this));
if (absGravity == Gravity.LEFT) {
mLockModeLeft = lockM
} else if (absGravity == Gravity.RIGHT) {
mLockModeRight = lockM
if (lockMode != LOCK_MODE_UNLOCKED) {
// Cancel interaction in progress
final ViewDragHelper helper = absGravity == Gravity.LEFT ? mLeftDragger : mRightD
helper.cancel();
switch (lockMode) {
case LOCK_MODE_LOCKED_OPEN:
final View toOpen = findDrawerWithGravity(absGravity);
if (toOpen != null) {
openDrawer(toOpen);
case LOCK_MODE_LOCKED_CLOSED:
final View toClose = findDrawerWithGravity(absGravity);
if (toClose != null) {
closeDrawer(toClose);
// default: do nothing
启用或禁用了所有的抽屉互动。
其他的很少用到了,就先介绍这么多,如果上面的内容不能满足你,可以去看源码,源码是最好的老师
您可能也会对以下文章感兴趣
QQ : 341470
Friend Link
New Member

我要回帖

更多关于 具有优势 英文 的文章

 

随机推荐