WELCOME Abdennour : Software engineer

Apr 27, 2012

Best Practices : Tuto2 Advanced Sliding Draw with Android





           SlidingDrawer's usage is very simple, to include the handle, and content.
*The handle is when you click on it, 
*the content or pumping drawer or shut up in adrawer.


 Much else to say, follow these steps.
1.A new Android project, named to bp002.SlidingDraw. (bp=best practices)
2.Prepare material, my icon here is the icon of the Launcher2 inside and put the drawable-hdpi file folder directory structure as follows:





3.Code of main.xml:
---------------------

  1. <?xml version="1.0" encoding="utf-8"?>     
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  3.     android:orientation="vertical"    
  4.     android:layout_width="fill_parent"    
  5.     android:layout_height="fill_parent"    
  6.     android:background="#808080"    
  7.     >     
  8. <SlidingDrawer     
  9.     android:id="@+id/slidingdrawer"    
  10.     android:layout_width="fill_parent"    
  11.     android:layout_height="fill_parent"    
  12.     android:orientation="vertical"    
  13.     android:handle="@+id/handle"    
  14.     android:content="@+id/content">     
  15.     <Button     
  16.             android:id="@+id/handle"    
  17.             android:layout_width="88dip"    
  18.             android:layout_height="44dip"    
  19.             android:background="@drawable/handle"    
  20.         />     
  21.     <LinearLayout     
  22.         android:id="@+id/content"    
  23.         android:layout_width="fill_parent"    
  24.         android:layout_height="fill_parent"    
  25.         android:background="#00ff00">     
  26.         <Button     
  27.             android:id="@+id/button"    
  28.             android:layout_width="wrap_content"    
  29.             android:layout_height="wrap_content"    
  30.             android:text="Button"    
  31.         />     
  32.         <EditText     
  33.             android:id="@+id/editText"    
  34.             android:layout_width="fill_parent"    
  35.             android:layout_height="wrap_content"    
  36.         />     
  37.     </LinearLayout>     
  38. </SlidingDrawer>     
  39. </LinearLayout>  



4.To Set handle icon style, add this code in handle.xml in drawable :





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





 runs it. Will get the following results:























References : 
-Matos' Tutorial.
-http://developer.android.com/index.html
-http://weizhulin.blog.51cto.com/1556324/311461

No comments:

Post a Comment