本文實例為大家分享了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>
新聞熱點
疑難解答
圖片精選