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 Device Monitor 的 File Explorer 中無(wú)法打開(kāi)某些文件夾的問(wèn)題
這篇文章主要介紹了解決Android Device Monitor 的 File Explorer 中無(wú)法打開(kāi)某些文件夾的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
Android?Hilt?Retrofit?Paging3使用實(shí)例
這篇文章主要介紹了Android?Hilt依賴注入的使用,首先,某個(gè)類的成員變量稱為依賴,如若此變量想要實(shí)例化引用其類的方法,可以通過(guò)構(gòu)造函數(shù)傳參或者通過(guò)某個(gè)方法獲取對(duì)象,此等通過(guò)外部方法獲取對(duì)象實(shí)例的稱為依賴注入2023-01-01
Android編程實(shí)現(xiàn)擦除Bitmap中某一塊的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)擦除Bitmap中某一塊的方法,涉及Android操作Bitmap顏色像素值調(diào)整的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11
Android 自定義布局豎向的ViewPager的實(shí)現(xiàn)
這篇文章主要介紹了Android 自定義布局豎向的ViewPager的實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android實(shí)現(xiàn)兩臺(tái)手機(jī)屏幕共享和遠(yuǎn)程控制功能
在遠(yuǎn)程協(xié)助、在線教學(xué)、技術(shù)支持等多種場(chǎng)景下,實(shí)時(shí)獲得另一部移動(dòng)設(shè)備的屏幕畫面,并對(duì)其進(jìn)行操作,具有極高的應(yīng)用價(jià)值,本項(xiàng)目旨在實(shí)現(xiàn)兩臺(tái) Android 手機(jī)之間的屏幕共享與遠(yuǎn)程控制,需要的朋友可以參考下2025-04-04
Android獲得所有存儲(chǔ)設(shè)備位置的最佳方法
今天小編就為大家分享一篇Android獲得所有存儲(chǔ)設(shè)備位置的最佳方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
Android工具類ImgUtil選擇相機(jī)和系統(tǒng)相冊(cè)
這篇文章主要為大家詳細(xì)介紹了Android工具類ImgUtil選擇相機(jī)和系統(tǒng)相冊(cè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10
flutter showModalBottomSheet常用屬性及說(shuō)明
這篇文章主要介紹了flutter showModalBottomSheet常用屬性及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09

