SlideringDrawer的使用(抽屉效果)
這是上下拉抽屜的效果,將 SlidingDrawer屬性設置為android:orientation="vertical"即可
二、重要屬性
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。
上面例子的布局文件:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="效果顯示:" /> <SlidingDrawer android:id="@+id/drawer1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:handle="@+id/layout1" android:content="@+id/mycontent1"> <LinearLayout android:id="@id/layout1" android:orientation="vertical" android:layout_width="35sp" android:layout_height="wrap_content" android:gravity="center"> <ImageView android:id="@+id/myImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/open" /> </LinearLayout> <GridView android:id="@id/mycontent1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numColumns="2" android:gravity="center" /> </SlidingDrawer> </LinearLayout> </FrameLayout>java文件:
import android.app.Activity; import android.os.Bundle; import android.widget.GridView; import android.widget.ImageView; import android.widget.SlidingDrawer; import android.widget.SlidingDrawer.OnDrawerCloseListener; import android.widget.SlidingDrawer.OnDrawerOpenListener; import android.widget.SlidingDrawer.OnDrawerScrollListener; public class SlidingDrawerActivity extends Activity { /** Called when the activity is first created. */ private SlidingDrawer sd; private GridView gv; private ImageView iv; private int [] itemIcons = new int [] { R.drawable.alarm, R.drawable.calendar, R.drawable.camera, R.drawable.clock, R.drawable.music, R.drawable.tv }; private String[] itemString = new String[]{"Alarm","Calendar","camera","clock","music","tv"}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.slidrawer); init(); GridAdapter adapter = new GridAdapter(SlidingDrawerActivity.this,itemString,itemIcons); gv.setAdapter(adapter); /* 設定SlidingDrawer被打開的事件處理 */ sd.setOnDrawerOpenListener(new OnDrawerOpenListener() { @Override public void onDrawerOpened() { // TODO Auto-generated method stub iv.setImageResource(R.drawable.close); } }); /* 設定SlidingDrawer被關閉的事件處理 */ sd.setOnDrawerCloseListener(new OnDrawerCloseListener() { public void onDrawerClosed() { iv.setImageResource(R.drawable.open); } }); sd.setOnDrawerScrollListener(new OnDrawerScrollListener() { @Override public void onScrollStarted() { // TODO Auto-generated method stub System.out.println("start"); } @Override public void onScrollEnded() { // TODO Auto-generated method stub System.out.println("end"); } }); } private void init(){ sd = (SlidingDrawer) findViewById(R.id.drawer1); gv = (GridView) findViewById(R.id.mycontent1); iv = (ImageView) findViewById(R.id.myImage); } }還有注意的是:
SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for ? ? ? instance,如果顯示的時候不正常,考慮上面的原因。
轉載于:https://www.cnblogs.com/android-html5/archive/2011/07/23/2534128.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的SlideringDrawer的使用(抽屉效果)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高性能JavaScript 读书笔记
- 下一篇: MindManager 报错:Click