編輯:關於Android編程
SlidingPaneLayout是Android團隊在2013年Google IO大會上更新的Support V4庫裡面的高級系統控件,它可以輕松的實現一些簡單的滑動菜單效果,例如QQ5.0上的菜單滑動效果,這篇博文來講講SlidingPaneLayout如何簡單使用。
先看一下效果圖
SlidingPaneLayout本質是一個水平的多層布局控件,下面簡單介紹下使用方法。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwPjGjutTaTWFpbkFjdGl2aXR5tcRhY3Rpdml0eV9tYWlusry+1s7EvP7A78PmzO2803N1cHBvcnQgdjSw/M/CtcRTbGlkaW5nUGFuZUxheW91dCCjqLXa0ru49kZyYW1lTGF5b3V0tPqx7bLLtaW1vLq9ytPNvKOstdq2/rj2RnJhbWVMYXlvdXS0+rHtxNrI3crTzbyjrMG91d+2vLvh1Nq0+sLr1tC2r8yszO2800ZyYWdtZW50o6mjujwvcD4NCjxwcmUgY2xhc3M9"brush:java;">
2:下面是這兩個Fragment和他們的布局文件,很簡單用於演示效果
菜單Fragment MenuFragment.Java
public class MenuFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { return inflater.inflate(R.layout.menu_layout, container, false); } }
菜單布局文件 menu_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@null" android:gravity="center_vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Menu0" android:layout_margin="20dp" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Menu1" android:layout_margin="20dp" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Menu2" android:layout_margin="20dp" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Menu3" android:layout_margin="20dp" android:textAppearance="?android:attr/textAppearanceLarge" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF5722" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:textStyle="bold" android:textSize="20sp" android:textColor="#ffffff" android:text="博客地址:http://blog.csdn.net/leejizhou" />