【移动应用开发技术】android如何实现筛选菜单效果_第1页
【移动应用开发技术】android如何实现筛选菜单效果_第2页
【移动应用开发技术】android如何实现筛选菜单效果_第3页
【移动应用开发技术】android如何实现筛选菜单效果_第4页
【移动应用开发技术】android如何实现筛选菜单效果_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

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

文档简介

【移动应用开发技术】android如何实现筛选菜单效果

这篇文章给大家分享的是有关android如何实现筛选菜单效果的内容。在下觉得挺实用的,因此分享给大家做个参考,一起跟随在下过来看看吧。实现步骤1、设置主题一般设置如下<style

name="Translucent_NoTitle"

parent="android:style/Theme.Dialog">

<item

name="android:windowNoTitle">true</item>

<item

name="android:background">#00000000</item>

<item

name="android:windowBackground">@android:color/transparent</item>

<item

name="android:windowAnimationStyle">@null</item>

<item

name="android:windowIsFloating">true</item>

<item

name="android:colorBackgroundCacheHint">@null</item>

<item

name="android:windowIsTranslucent">true</item>

<item

name="android:backgroundDimEnabled">false</item><span

>

</span>背景暗淡效果

</style>也可使用android.R.style.Theme_Panel和android.R.style.Theme_Light_Panel。android.R.style.Theme_Panel代码如下,其与上面是一样的。<style

name="Theme.Panel">

<item

name="windowBackground">@color/transparent</item>

<item

name="colorBackgroundCacheHint">@null</item>

<item

name="windowFrame">@null</item>

<item

name="windowContentOverlay">@null</item>

<item

name="windowAnimationStyle">@null</item>

<item

name="windowIsFloating">true</item>

<item

name="backgroundDimEnabled">false</item>

<item

name="windowIsTranslucent">true</item>

<item

name="windowNoTitle">true</item>

</style>2、设置内容的宽高我们通过WindowManager.LayoutParams实现。WindowManager.LayoutParams

layoutParams

=

getWindow().getAttributes();

layoutParams.width

=

screenWidth;

layoutParams.height

=

contentHeight;

layoutParams.gravity

=

Gravity.TOP;

layoutParams.flags

|=

WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;

//不阻塞事件传递到后面的窗口

getWindow().setAttributes(layoutParams);这里,设置layoutParams.flags|=WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;则后面窗口的按钮可响应触摸事件(例,HorizontalScrollView能横向滚动)。3、设置动画通过ValueAnimator实现。enter

=

ValueAnimator.ofFloat(0,

1f).setDuration(350);

enter.addUpdateListener(new

ValueAnimator.AnimatorUpdateListener()

{

@Override

public

void

onAnimationUpdate(ValueAnimator

animation)

{

dialogContent.setTranslationY((1

-

animation.getAnimatedFraction())

*

-contentHeight);

}

});

out

=

ValueAnimator.ofFloat(0,

1f).setDuration(350);

out.addUpdateListener(new

ValueAnimator.AnimatorUpdateListener()

{

@Override

public

void

onAnimationUpdate(ValueAnimator

animation)

{

dialogContent.setTranslationY(animation.getAnimatedFraction()

*

-contentHeight);

}

});

out.addListener(new

Animator.AnimatorListener()

{

@Override

public

void

onAnimationStart(Animator

animation)

{

}

@Override

public

void

onAnimationEnd(Animator

animation)

{

dismiss();

}

@Override

public

void

onAnimationCancel(Animator

animation)

{

}

@Override

public

void

onAnimationRepeat(Animator

animation)

{

}

});上面enter和out进行一系列设置,对out动画加开始结束监听。enter的start()方法在onStart()中调用@Override

protected

void

onStart()

{

super.onStart();

dialogContent.post(new

Runnable()

{

@Override

public

void

run()

{

enter.start();

}

});

}通过view的post方式,enter.start()会在view

hierarchy(view树)构建完后执行(即视图构建完后执行)。view.post源码:public

boolean

post(Runnable

action)

{

final

AttachInfo

attachInfo

=

mAttachInfo;

if

(attachInfo

!=

null)

{

return

attachInfo.mHandler.post(action);

}

//

Assume

that

post

will

succeed

later

ViewRootImpl.getRunQueue().post(action);

return

true;

}第七行为关键代码,ViewRootImpl为视图层级的顶部,实现了view和WindowManager之间的必要协议。RunQueue:运行队列用来排入没有handler关联的view的以后工作。所以这里dialog的视图显示时会调用enter.start()方法.监听返回键:@Override

public

boolean

onKeyDown(int

keyCode,

KeyEvent

event)

{

if

(keyCode

==

KeyEvent.KEYCODE_BACK)

{

out.start();

return

true;

}

return

super.onKeyDown(keyCode,

event);

}out动画执行完后,onAnimationEnd中调用dismiss()方法。4、在点击的view下显示出来public

void

showAsDropView(View

view)

{

WindowManager.LayoutParams

lp

=

getWindow().getAttributes();

lp.width

=

screenWidth;

int[]

location

=

new

int[2];

view.getLocationOnScreen(location);

//

view.getLocationInWindow(location);<span

>

</span>这里跟上面一句的效果一样,不知有什么区别

lp.y

=

location[1]-PhoneConstant.statusHeight+view.getHeight();

lp.gravity

=

Gravity.TOP;

getWindow().setAttributes(lp);

contentTop

=

location[1];

show();

}PhoneConstant.statusHeight为状态栏的高度,其通过反射获取//反射获取状态栏高度

Class<?>

c

=

null;

Object

obj

=

null;

Field

field

=

null;

int

x

=

0,

sbar

=

0;

try

{

c

=

Class.forName("ernal.R$dimen");

obj

=

c.newInstance();

field

=

c.getField("status_bar_height");

x

=

Integer.parseInt(field.get(obj).toString());

PhoneConstant.statusHeight

=

getResources().getDimensionPixelSize(x);

}

catch(Exception

e1)

{

e1.printStackTrace();

}也可通过以下方式获取Rect

outRect

=

new

Rect();

activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);不过直接放在activity的onCreate中无效,只有界面绘制出来了才能获取到,可通过view.post()方式获取。效果图:另外,继承自AlertDialog的自定义dialog点击edittext不弹出软键盘,所以一般继承自Dialo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论