Android自定义View-九宫格抽奖转盘(两种实现)

好久没写文章了,一来感觉自己技术没啥进步,二来各种杂事繁忙,以至于拖了许久。正好这个版本产品需求需要做一个九宫格样式的转盘抽奖机,感觉是个挺有意思的东西,把我的解决方案和中间遇到的问题发出来,供大家参考哈~

两种方案,先看成品的效果
在这里插入图片描述

开始做这个功能的时候,跟产品确定效果,要求动画是先慢后快再变慢,我第一时间想到的就是插值器。AccelerateDecelerateInterpolator就是属于开始和结束很慢,中间速度较快的那种插值器,完美符合需求。接下来需要考虑怎么来实现九宫格。

第一种实现

我第一版的实现是使用ConstraintLayout,根据约束条件来进行九宫格的布局,这样的缺点是布局文件难看,过多的include,实现起来倒是不怎么复杂。先来看下方案的代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

        <include
            android:id="@+id/include_lottery0"
            layout="@layout/layout_lottery_item"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <include
            android:id="@+id/include_lottery1"
            layout="@layout/layout_lottery_item"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintLeft_toRightOf="@+id/include_lottery0"
            app:layout_constraintRight_toLeftOf="@+id/include_lottery2"
            app:layout_constraintTop_toTopOf="parent" />

        <include
            android:id="@+id/include_lottery2"
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值