Android 自定义投票功能实现

效果图

Alt

实现思路

主要通过RecyclerView实现,通过RecyclerView的局部刷新来对item进行属性动画,完成投票

RecyclerView的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/vote_rv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        tools:itemCount="3"
        tools:listitem="@layout/vote_item" />
</LinearLayout>

RecyclerView的item布局

布局思路:
通过嵌套两个矩形view,通过动画来改变第二个view的移动(属性动画实现).里面有些样式我没有贴出来,可以根据自己需求进行改变

<?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:id="@+id/vote_lay"
    android:layout_width="match_parent"
    android:layout_height="44dp"
    android:layout_marginTop="12dp"
    android:background="@drawable/layer_dedee0">

    <View
        android:id="@+id/vote_result_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/shape_e0ffee_corner8"
        android:visibility="gone"
        app:layout_constraintStart_toStartOf="parent" />

    <View
        android:id="@+id/choose_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/shape_e0ffee_corner8"
        android:visibility="gone"
        android:layout_margin="1dp"
        app:layout_constraintStart_toStartOf="parent" />

    <TextView
        android:id="@+id/vote_tv"
        android:layout_width="wrap_content"
        android:layout_height="24dp"
        android:text="从未在一起"
        android:textColor="#333333"
        android:textSize="16dp"
        android:textStyle="normal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/choose_vote_tv"
        android:layout_width="wrap_content"
        android:layout_height="24dp"
        android:layout_marginStart="20dp"
        android:text="从未在一起"
        android:textColor="#333333"
        android:textSize="16dp"
        android:textStyle="normal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:visibility="gone"/>

    <TextView
        android:id="@+id/progress_tv"
        android:layout_width="wrap_content"
        android:layout_height="24dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="16dp"
        <
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值