当前位置: 移动技术网 > IT编程>移动开发>Android > Android SlidingDrawer 抽屉效果的实现

Android SlidingDrawer 抽屉效果的实现

2019年07月24日  | 移动技术网IT编程  | 我要评论

收音机室外天线,蓓舒宁,李方丁个人资料

slidingdrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容。它可以垂直或水平滑动,它有俩个view组成,其一是可以拖动的handle,其二是隐藏内容的view.它里面的控件必须设置布局,在布局文件中必须指定handle和content。

1、布局layou文件

复制代码 代码如下:

<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="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<slidingdrawer
  android:id="@+id/slidingdrawer"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:content="@+id/content"
  android:handle="@+id/handle"
  android:orientation="vertical" >
  <button
    android:id="@+id/handle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="slidingdraser" />
  <linearlayout <!--隐藏的内容-->
    android:id="@+id/content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#00ffaa" >
    <button
      android:id="@+id/button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="button" />
    <edittext
      android:id="@+id/edittext"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" />
  </linearlayout>
</slidingdrawer>
</linearlayout>


 2、下面是运行程序之后的界面

另:可在drawable中添加文件

复制代码 代码如下:

    <?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
        <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/handle_normal" /> 
        <item android:state_pressed="true" android:drawable="@drawable/handle_pressed" /> 
        <item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/handle_focused" /> 
        <item android:state_enabled="true" android:drawable="@drawable/handle_normal" /> 
        <item android:state_focused="true" android:drawable="@drawable/handle_focused" /> 
    </selector> 

总结:

1、重要属性

  android:allowsingletap:指示是否可以通过handle打开或关闭

  android:animateonclick:指示是否当使用者按下手柄打开/关闭时是否该有一个动画。

  android:content:隐藏的内容

  android:handle:handle(手柄)

2、重要方法

  animateclose():关闭时实现动画。

  close():即时关闭

  getcontent():获取内容

  ismoving():指示slidingdrawer是否在移动。

  isopened():指示slidingdrawer是否已全部打开

  lock():屏蔽触摸事件。

  setondrawercloselistener(slidingdrawer.ondrawercloselistener ondrawercloselistener):slidingdrawer关闭时调用

  setondraweropenlistener

  setondrawerscrolllistener

  unlock():解除屏蔽触摸事件。

  toggle():切换打开和关闭的抽屉slidingdrawer。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网