歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android: SlidingDrawer 抽屜效果

Android: SlidingDrawer 抽屜效果 (Gesture View Like Facebook Notification)

要是實現這樣的功能很簡單,就是SlidingDrawer的使用

效果如下圖:手指按住Notification往上/往下拉動,顯示/隱藏notification content


XML

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout android:id="@+id/LinearLayout01"  
  3.     android:layout_width="fill_parent" android:layout_height="fill_parent"  
  4.     xmlns:android="http://schemas.android.com/apk/res/android"  
  5.     android:orientation="vertical" android:gravity="bottom">  
  6.     <SlidingDrawer android:layout_width="wrap_content"  
  7.         android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"  
  8.         android:content="@+id/contentLayout" android:padding="10dip"  
  9.         android:layout_height="200dip">  
  10.         <Button android:layout_width="wrap_content"  
  11.             android:layout_height="wrap_content" android:id="@+id/slideHandleButton"  
  12.             android:background="@drawable/arrowup"></Button>  
  13.         <LinearLayout android:layout_width="wrap_content"  
  14.             android:id="@+id/contentLayout" android:orientation="vertical"  
  15.             android:gravity="center|top" android:padding="10dip"  
  16.             android:background="#505050" android:layout_height="wrap_content">  
  17.             <TextView android:id="@+id/TextView01" android:layout_width="wrap_content"  
  18.                 android:layout_height="fill_parent" android:layout_weight="8" android:text="Hello Slider"></TextView>  
  19.             <Button android:id="@+id/Button02" android:layout_weight="2" android:layout_width="wrap_content"  
  20.                 android:layout_height="wrap_content" android:text="Do anything"></Button>  
  21.         </LinearLayout>  
  22.     </SlidingDrawer>  
  23. </LinearLayout>  

activity

  1. public class SliderActivity extends Activity {  
  2.     Button slideHandleButton;  
  3.     SlidingDrawer slidingDrawer;  
  4.   
  5.     @Override  
  6.     public void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.   
  9.         setContentView(R.layout.main);  
  10.         slideHandleButton = (Button) findViewById(R.id.slideHandleButton);  
  11.         slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);  
  12.   
  13.         slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {  
  14.             @Override  
  15.             public void onDrawerOpened() {  
  16.                 slideHandleButton.setBackgroundResource(R.drawable.arrowdown);  
  17.             }  
  18.         });  
  19.   
  20.         slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {  
  21.             @Override  
  22.             public void onDrawerClosed() {  
  23.                 slideHandleButton.setBackgroundResource(R.drawable.arrowup);  
  24.             }  
  25.         });  
  26.     }  
  27. }  

不用講解,layout.xml和java代碼很清晰。

Copyright © Linux教程網 All Rights Reserved