Android自定義view仿QQ的Tab按鈕動(dòng)畫效果(示例代碼)
話不多說(shuō) 先上效果圖
實(shí)現(xiàn)其實(shí)很簡(jiǎn)單,先用兩張圖
一張是背景的圖,一張是笑臉的圖片,笑臉的圖片是白色,可能看不出來(lái)。實(shí)現(xiàn)思路:主要是再觸摸view的時(shí)候同時(shí)移動(dòng)這兩個(gè)圖片,但是移動(dòng)的距離不一樣,造成的錯(cuò)位感,代碼很簡(jiǎn)單:
import android.content.Context import android.graphics.* import android.util.AttributeSet import android.view.MotionEvent import android.view.View import com.example.dawnmvvm.R import com.example.dawnmvvm.util.LogUtil class MyDrawBitmap @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0) : View(context, attrs, defStyleAttr, defStyleRes) { private var dx = 0f private var dy = 0f private var dx1 =0f private var dy1 = 0f private val bitmap: Bitmap by lazy { BitmapFactory.decodeResource(resources, R.drawable.bg_tab);//背景 } private val bitmap2: Bitmap by lazy { BitmapFactory.decodeResource(resources, R.drawable.img_smile);//笑臉 } override fun draw(canvas: Canvas?) { super.draw(canvas) LogUtil.e("MyDrawBitmap===x===${dx}") LogUtil.e("MyDrawBitmap===y===${dy}") if(dx<0){ dx=0f } if(dy<0){ dy=0f; } canvas?.drawBitmap(bitmap, dx, dy, null);//移動(dòng)背景 canvas?.drawBitmap(bitmap2, dx1, dy1, null);//移動(dòng)笑臉 } override fun onTouchEvent(event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_UP-> { dx = 0f dy = 0f dx1 = 0f dy1 = 0f } else->{ dx = event.x/20f dy = event.y/20f dx1 = event.x/10f dy1 = event.y/10f } } invalidate() return true; } }
是不是很簡(jiǎn)單,不過(guò)不是很完美
到此這篇關(guān)于Android自定義view仿QQ的Tab按鈕動(dòng)效效果(示例代碼)的文章就介紹到這了,更多相關(guān)Android仿QQ的Tab按鈕動(dòng)效內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Android開發(fā)教程之如何屏蔽View的重復(fù)點(diǎn)擊
- Android自定義view實(shí)現(xiàn)輸入框效果
- Android實(shí)現(xiàn)的RecyclerView適配器
- Android自定義View仿大眾點(diǎn)評(píng)星星評(píng)分控件
- Android自定義View實(shí)現(xiàn)雪花特效
- Android Filterable實(shí)現(xiàn)Recyclerview篩選功能的示例代碼
- Android 滑動(dòng)Scrollview標(biāo)題欄漸變效果(仿京東toolbar)
- Android自定義View實(shí)現(xiàn)圓弧進(jìn)度的效果
- Android使用ScrollView實(shí)現(xiàn)滾動(dòng)效果
- Android自定義view之圍棋動(dòng)畫效果的實(shí)現(xiàn)
- Android自定義View實(shí)現(xiàn)分段選擇按鈕的實(shí)現(xiàn)代碼
- 詳解Android WebView監(jiān)聽console錯(cuò)誤信息
- Android 處理 View 重復(fù)點(diǎn)擊的多種方法
相關(guān)文章
Android實(shí)現(xiàn)屏幕截圖并保存截圖到指定文件
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)屏幕截圖并保存截取圖片到指定文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10Android ViewPager畫廊效果詳解及實(shí)例
這篇文章主要介紹了Android ViewPager畫廊效果詳解及實(shí)例的相關(guān)資料,這里提供實(shí)例代碼及實(shí)現(xiàn)效果圖,具有參考價(jià)值,需要的朋友可以參考下2016-12-12Android中創(chuàng)建快捷方式及刪除快捷方式實(shí)現(xiàn)方法
這篇文章主要介紹了Android中創(chuàng)建快捷方式及刪除快捷方式實(shí)現(xiàn)方法,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-06-06Android編程將Activity背景設(shè)置為墻紙的簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要介紹了Android編程將Activity背景設(shè)置為墻紙的簡(jiǎn)單實(shí)現(xiàn)方法,涉及Android簡(jiǎn)單的屬性設(shè)置及XML配置修改等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10Android 廣播大全 Intent Action 事件詳解
這篇文章主要給大家介紹Android 廣播大全 Intent Action 事件詳解,涉及到android廣播action 方面知識(shí)點(diǎn),本文講解的非常的全面,感興趣的朋友一起看看吧2015-10-10