先上效果圖:
該控件用法簡單,如果自己加以美化,定能做出很炫的想要的效果
一、SlidingDrawer隱藏屏外的內容,並允許用戶通過handle以顯示隱藏內容。它可以垂直或水平滑動,它有倆個View組成,其一是可以拖動的handle,其二是隱藏內容的View.它裏面的控件必須設置佈局,在佈局文件中必須指定handle和content.
二、重要屬性
android:allowSingleTap:指示是否可以通過handle打開或關閉
android:animateOnClick:指示是否當使用者按下手柄打開/關閉時是否該有一個動畫。
android:content:隱藏的內容
android:handle:handle(手柄)
三、重要方法
animateClose():關閉時實現動畫。
close():即時關閉
getContent():獲取內容
isMoving():指示SlidingDrawer是否在移動。
isOpened():指示SlidingDrawer是否已全部打開
lock():屏蔽觸摸事件。
setOnDrawerCloseListener(SlidingDrawer.OnDrawerCloseListener onDrawerCloseListener):SlidingDrawer關閉時調用
unlock():解除屏蔽觸摸事件。
toggle():切換打開和關閉的抽屜SlidingDrawer。
四、完整實例
佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<SlidingDrawer
android:orientation="horizontal"
android:id="@+id/sl"
android:content="@+id/tex"
android:handle="@+id/but"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_world" >
<ImageView
android:id="@id/tex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
/>
<Button
android:text="打開"
android:id="@id/but"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</Button>
</SlidingDrawer>
</RelativeLayout>
主Activity
package com.example.slidingdrawer;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SlidingDrawer;
public class MainActivity extends Activity {
SlidingDrawer slidingDrawer ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
簡單的用法就大概這樣,至於要用到別的,自行增添。