實現類似launcher的滑動桌面

2021-08-26 11:18:15 字數 1347 閱讀 3064

這個例子中涉及到了以下幾個知識點:

接下來說一下我實現的

思路

2) 由於要實現隨手勢滑動,所以只要實現gesturedetector.ongesturelistener介面中的ondown()、onscroll()方法就可以

3)由於要接收觸屏事件,所以要實現ontouchevent()

接下來我們來看一下**吧:

public class scrolllayout extends linearlayout implements gesturedetector.ongesturelistener public scrolllayout(context context, attributeset attrs) private void init() //返回值為true 才能觸發 手勢事件 public boolean ondown(motionevent e) public void onshowpress(motionevent e) public boolean onsingletapup(motionevent e) //順手勢滑動 public boolean onscroll(motionevent e1, motionevent e2, float distancex, float distancey) else if(offset < -1*childwidth*(childcount-1)) //重繪布局 requestlayout(); return true; } public void onlongpress(motionevent e) public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) //設定布局檔案的寬高和每個桌面的寬高 @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) //設定距離(0,0)點x軸方向的初始距離 int left = 0+offset; for (int i = 0; i < childcount ; i ++) } } //觸屏事件 @override public boolean ontouchevent(motionevent event) return result; } //判斷當手指抬起時顯示那個桌面 private void showonedesktop() offset = offset > 0 ? index*childwidth : -1*index*childwidth; requestlayout(); } }

在這段**中使用到的attrs.xml檔案:

使用:

<?xml version="1.0" encoding="utf-8"?>

用swiper實現類似淘搶購的滑動tab效果

en class timeaxis warp class timeaxis current class swiper container id swiper container3 class class swiper slide data num 0 class timeaxis item inne...

類似滑動蘋果解鎖Text

自定義textview import android.content.context import android.graphics.canvas import android.graphics.lineargradient import android.graphics.matrix import...

MFC實現遊戲Launcher效果

一般遊戲的launcher視窗或者splash視窗都有比較玄的半透明效果。普通的通過鏤空視窗形成的異形視窗無法支援半透明效果,下面介紹一種通過繪製半透明png的方式來實現這種效果的方法。如果視窗不需要拖動,簡單點,用gdi 在 onerasebkgnd 或者 onpaint 繪製png就可以實現。如...