Android星級評分條實現(xiàn)評分界面
本文實例為大家分享了Android實現(xiàn)簡單評分界面制作的具體代碼,供大家參考,具體內(nèi)容如下
簡單評分界面的制作
實現(xiàn)如圖界面

1.先布局,創(chuàng)建布局文件,使用相對布局,添加一個編輯框,一個文本框,一個評分條,再加一個按鈕。
<?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="請評價店鋪的服務態(tài)度與服務質量" ? ? ? ? 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="店鋪評分" ? ? ? ? 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=""來設置 ? ? ? ? android:stepSize="1"http://設置每次一顆一顆增加 ? ? ? ? android:rating="5"http://設置默認五顆星都是亮的 ? ? ? ? /> ? ? <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ā)表評價"/> </RelativeLayout>
接下來在java代碼當中實現(xiàn)對按鈕監(jiān)聽
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();//獲取當前的星數(shù)
? ? ? ? ? ? ? ? Toast.makeText(RatingBar_Activity.this,"你評價了"+rating+"顆星",Toast.LENGTH_LONG).show();
? ? ? ? ? ? }
? ? ? ? });
? ? }
}以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
解決Android Device Monitor 的 File Explorer 中無法打開某些文件夾的問題
這篇文章主要介紹了解決Android Device Monitor 的 File Explorer 中無法打開某些文件夾的問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
Android?Hilt?Retrofit?Paging3使用實例
這篇文章主要介紹了Android?Hilt依賴注入的使用,首先,某個類的成員變量稱為依賴,如若此變量想要實例化引用其類的方法,可以通過構造函數(shù)傳參或者通過某個方法獲取對象,此等通過外部方法獲取對象實例的稱為依賴注入2023-01-01
Android編程實現(xiàn)擦除Bitmap中某一塊的方法
這篇文章主要介紹了Android編程實現(xiàn)擦除Bitmap中某一塊的方法,涉及Android操作Bitmap顏色像素值調整的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11
Android 自定義布局豎向的ViewPager的實現(xiàn)
這篇文章主要介紹了Android 自定義布局豎向的ViewPager的實現(xiàn)的相關資料,需要的朋友可以參考下2017-05-05
Android實現(xiàn)兩臺手機屏幕共享和遠程控制功能
在遠程協(xié)助、在線教學、技術支持等多種場景下,實時獲得另一部移動設備的屏幕畫面,并對其進行操作,具有極高的應用價值,本項目旨在實現(xiàn)兩臺 Android 手機之間的屏幕共享與遠程控制,需要的朋友可以參考下2025-04-04
Android工具類ImgUtil選擇相機和系統(tǒng)相冊
這篇文章主要為大家詳細介紹了Android工具類ImgUtil選擇相機和系統(tǒng)相冊,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-10-10
flutter showModalBottomSheet常用屬性及說明
這篇文章主要介紹了flutter showModalBottomSheet常用屬性及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09

