首页 > 系统 > Android > 正文

Android使用RecyclerView实现投票系统

2020-07-28 14:09:03
字体:
来源:转载
供稿:网友

本文实例为大家分享了Android投票系统的具体代码,供大家参考,具体内容如下

一、创建一个fragment_vote_list.xml用来显示投票的主页面

(1)标题栏使用Toolbar
(2)投票区域可以滑动,使用RecyclerView实现

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:andro android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:clickable="true" android:background="@color/backgroundColorWhite"> <LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:background="@color/backgroundColorWhite"  android:orientation="vertical">  <android.support.v7.widget.Toolbar   android:   android:layout_width="match_parent"   android:layout_height="@dimen/toolbarHeight"   android:background="@color/backgroundColorWhite"   app:contentInsetStart="0dp">   <RelativeLayout    android:layout_width="match_parent"    android:layout_height="match_parent">    <Button     android:     android:layout_width="@dimen/titleBarBackWidth"     android:layout_height="@dimen/titleBarBackHeight"     android:layout_margin="@dimen/margin_min"     android:layout_centerVertical="true"     android:background="@drawable/titlebar_back"     android:layout_marginLeft="@dimen/padding_20"     />    <TextView     android:     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerInParent="true"     android:layout_gravity="center_vertical"     android:text="投票"     android:textColor="@color/textcolor_28282d"     android:textSize="@dimen/textSizeMax"     android:textStyle="bold"/>   </RelativeLayout>  </android.support.v7.widget.Toolbar>  <android.support.v7.widget.RecyclerView   android:   android:layout_width="match_parent"   android:layout_height="match_parent">  </android.support.v7.widget.RecyclerView> </LinearLayout></RelativeLayout>

注:界面字体大小以及控件宽度自行调整即可,使用RecyclerView首先需要在项目的build.gradle中添加相应的依赖库才行。添加:implementation ‘com.android.support:recyclerview-v7:24.2.1'

界面效果:

二、创建一个item_vote.xml用来显示投票的具体内容

(1)主布局使用LinearLayout实现,里面添加一个TextView用来显示投票的问题,使用CheckBox作为投票的多选框。
(2)将当前的Item加载到投票的主页面中

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:andro android:orientation="vertical"  android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/backgroundColorWhite" > <TextView  android:  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="1.请问你支持哪一个决议?"  android:textColor="@color/black"  android:textSize="@dimen/item_vote_question"  android:layout_marginLeft="@dimen/padding_20" /> <LinearLayout  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:background="@color/backgroundColorWhite"  android:orientation="vertical"  android:layout_margin="@dimen/padding_20">  <CheckBox   android:   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:text="AAAAAA"   android:textColor="@color/black"   android:textSize="@dimen/item_vote_answer" />  <CheckBox   android:   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:text="BBBBBBB"   android:textColor="@color/black"   android:textSize="@dimen/item_vote_answer" />  <CheckBox   android:   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:text="BCCCCC"   android:textColor="@color/black"   android:textSize="@dimen/item_vote_answer" /> </LinearLayout> </LinearLayout>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表