Android SlidingDrawer 抽屉效果的实现

2016-02-19 10:21 4 1 收藏

想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的Android SlidingDrawer 抽屉效果的实现教程,一起来看看吧!超容易上手~

【 tulaoshi.com - 编程语言 】

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

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

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 

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

总结:

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。

来源:https://www.tulaoshi.com/n/20160219/1594355.html

延伸阅读
代码如下: RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gallerylayout" android:layout_width="fill_parent" android:layout_height="fill_parent" Gallery android:id="@+id/overview" android:layout_width="fill_parent" android:layout_height="wrap_content" / ImageView a...
TabWidget类似于Android 中查看电话薄的界面,通过多个标签切换显示不同内容。要实现这一效果,首先要了解TabHost,它是一个用来存放多个Tab标签的容器。每一个Tab都可以对应自己的布局,比如,电话薄中的Tab布局就是一个List的线性布局了。  要使用TabHost,首先需要通过getTabHost方法来获取TabHost的对象,然后通过addTab方法来向TabHos...
一、在drawable下面添加xml文件rounded_editview.xml 代码如下: ?xml version="1.0" encoding="utf-8"? shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle"     solid android:color="#FFFFFF"/solid     padding android:left="10dp"  ...
去掉标题栏: requestWindowFeature(Window.FEATURE_NO_TITLE); API上是这么说的: int     FEATURE_NO_TITLE     Flag for the "no title" feature, turning off the title at the top of the screen. 屏幕全屏: getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); API上是这么说的...
代码如下: public class MirrorView extends View {  Paint m_paint;  int m_nShadowH;  Drawable m_dw;  Bitmap m_bitmap;  //xxxx  Matrix mMatrix;  int shadowHeight;  public MirrorView(Context context, Bitmap bitmap) {   super(context);   m_bitmap = bitmap;   _Init(); ...

经验教程

663

收藏

98
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部