Android星級(jí)評(píng)分條實(shí)現(xiàn)評(píng)分界面
本文實(shí)例為大家分享了Android實(shí)現(xiàn)簡(jiǎn)單評(píng)分界面制作的具體代碼,供大家參考,具體內(nèi)容如下
簡(jiǎn)單評(píng)分界面的制作
實(shí)現(xiàn)如圖界面
1.先布局,創(chuàng)建布局文件,使用相對(duì)布局,添加一個(gè)編輯框,一個(gè)文本框,一個(gè)評(píng)分條,再加一個(gè)按鈕。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout ? ? xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:orientation="vertical" ? ? xmlns:tools="http://schemas.android.com/tools" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent"> ? ? <EditText ? ? ? ? android:id="@+id/etxt" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:lines="5" ? ? ? ? android:hint="請(qǐng)?jiān)u價(jià)店鋪的服務(wù)態(tài)度與服務(wù)質(zhì)量" ? ? ? ? android:textSize="20sp"/> ? ? <TextView ? ? ? ? android:id="@+id/txt" ? ? ? ? android:layout_below="@id/etxt" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:gravity="center" ? ? ? ? android:text="店鋪評(píng)分" ? ? ? ? android:layout_marginTop="20dp" ? ? ? ? android:textSize="20sp"/> ? ? <RatingBar ? ? ? ? android:id="@+id/ratingbar" ? ? ? ? android:layout_width="wrap_content" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:layout_below="@id/txt"http://使用numStars=""來(lái)設(shè)置 ? ? ? ? android:stepSize="1"http://設(shè)置每次一顆一顆增加 ? ? ? ? android:rating="5"http://設(shè)置默認(rèn)五顆星都是亮的 ? ? ? ? /> ? ? <Button ? ? ? ? android:id="@+id/btn" ? ? ? ? android:layout_below="@id/ratingbar" ? ? ? ? android:layout_width="wrap_content" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:layout_alignRight="@id/txt" ? ? ? ? android:text="發(fā)表評(píng)價(jià)"/> </RelativeLayout>
接下來(lái)在java代碼當(dāng)中實(shí)現(xiàn)對(duì)按鈕監(jiān)聽(tīng)
package com.example.relativelayout; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.RatingBar; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class RatingBar_Activity ?extends AppCompatActivity { ? ? private RatingBar ratingBar; ? ? @Override ? ? protected void onCreate(Bundle savedInstanceState) { ? ? ? ? super.onCreate(savedInstanceState); ? ? ? ? setContentView(R.layout.ratingbar_main); ? ? ? ? ratingBar=findViewById(R.id.ratingbar); ? ? ? ? Button btn=findViewById(R.id.btn); ? ? ? ? btn.setOnClickListener(new View.OnClickListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void onClick(View v) { ? ? ? ? ? ? ? ? float rating=ratingBar.getRating();//獲取當(dāng)前的星數(shù) ? ? ? ? ? ? ? ? Toast.makeText(RatingBar_Activity.this,"你評(píng)價(jià)了"+rating+"顆星",Toast.LENGTH_LONG).show(); ? ? ? ? ? ? } ? ? ? ? }); ? ? } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android ListView滑動(dòng)改變標(biāo)題欄背景漸變效果
這篇文章主要為大家詳細(xì)介紹了Android ListView滑動(dòng)改變標(biāo)題欄背景漸變效果,透明轉(zhuǎn)變成不透明,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07Android編程實(shí)現(xiàn)自定義控件的方法示例
這篇文章主要介紹了Android編程實(shí)現(xiàn)自定義控件的方法,結(jié)合實(shí)例形式分析了Android自定義控件的布局、功能實(shí)現(xiàn)與使用技巧,需要的朋友可以參考下2017-06-06Android中使用socket使底層和framework通信的實(shí)現(xiàn)方法
native和framework的通信是通過(guò)jni,但是這一般只是framework調(diào)用native,native如果有消息要怎樣通知上層 呢?android中GSP模塊提供一種解決思路,但是實(shí)現(xiàn)有些復(fù)雜,這里介紹一種使用socket通信的方法可以使native和framework自由通信,感興趣的朋友一起看看吧2016-11-11在android中ScrollView嵌套ScrollView解決方案
大家好,眾所周知,android里兩個(gè)相同方向的ScrollView是不能嵌套的,那要是有這樣的需求怎么辦,接下來(lái)為您介紹解決方法,感興趣的朋友可以了解下2013-01-01Android?ANR分析trace文件的產(chǎn)生流程詳情
這篇文章主要介紹了Android?ANR分析trace文件的產(chǎn)生流程詳情,文章圍繞主題展開(kāi)相詳細(xì)的內(nèi)容介紹,需要的朋友可以參考一下2022-07-07android panellistview 圓角實(shí)現(xiàn)代碼
android panellistview 圓角是每一個(gè)android開(kāi)發(fā)者都具備的一項(xiàng),對(duì)于新手朋友來(lái)說(shuō)可能有點(diǎn)難度,接下來(lái)將詳細(xì)介紹,需要了解的朋友可以參考下2012-12-12Android 避免APP啟動(dòng)閃黑屏的解決辦法(Theme和Style)
閃黑屏的原因主要是我們啟動(dòng)Activity的時(shí)候,需要跑完onCreate和onResume才會(huì)顯示界面2013-07-07Android 錢(qián)包支付之輸入支付密碼的實(shí)現(xiàn)步驟
這篇文章主要介紹了Android 錢(qián)包支付之輸入支付密碼,需要的朋友可以參考下2018-04-04