Android投票
效果图
实现思路
主要通过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"
<