欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android自定義view仿QQ的Tab按鈕動(dòng)畫效果(示例代碼)

 更新時(shí)間:2021年01月24日 14:50:42   作者:曉夢(mèng)千年  
這篇文章主要介紹了Android自定義view仿QQ的Tab按鈕動(dòng)畫效果(示例代碼),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考價(jià)值,需要的朋友可以參考下

話不多說(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)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論