歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android教程:使用ViewPager實現高仿launcher拖動效果

Android教程:使用ViewPager實現高仿launcher拖動效果

日期:2017/3/1 10:25:56   编辑:Linux編程

前面一篇高仿launcher和墨跡左右拖動效果獲得了很多朋友的好評,上一篇文章 主要是通過自定義ViewGroup實現的,有點麻煩。今天用ViewPager 這個類實現了同樣的效果,這樣代碼更少,但是效果是一樣的。ViewPager是實現左右兩個屏幕平滑地切換的一個類,它是Google提供的。

使用ViewPager首先需要引入Android-support-v4.jar這個jar包。具體ViewPager的用法,這裡不做介紹,自己從網上搜索吧!

下面先看一下效果:


效果請自行體驗和上一篇比較。下面上代碼:

首先是layout下面的main.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <android.support.v4.view.ViewPager
  7. android:id="@+id/viewPager"
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content" />
  10. <RelativeLayout
  11. android:layout_width="fill_parent"
  12. android:layout_height="wrap_content"
  13. android:orientation="vertical" >
  14. <LinearLayout
  15. android:id="@+id/viewGroup"
  16. android:layout_width="fill_parent"
  17. android:layout_height="wrap_content"
  18. android:layout_alignParentBottom="true"
  19. android:layout_marginBottom="30dp"
  20. android:gravity="center_horizontal"
  21. android:orientation="horizontal" >
  22. </LinearLayout>
  23. </RelativeLayout>
  24. </FrameLayout>
Copyright © Linux教程網 All Rights Reserved