網站首頁 編程語言 正文
本文實例為大家分享了Android實現簡單評分界面制作的具體代碼,供大家參考,具體內容如下
簡單評分界面的制作
實現如圖界面
1.先布局,創建布局文件,使用相對布局,添加一個編輯框,一個文本框,一個評分條,再加一個按鈕。
<?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="請評價店鋪的服務態度與服務質量" ? ? ? ? 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="發表評價"/> </RelativeLayout>
接下來在java代碼當中實現對按鈕監聽
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();//獲取當前的星數
? ? ? ? ? ? ? ? Toast.makeText(RatingBar_Activity.this,"你評價了"+rating+"顆星",Toast.LENGTH_LONG).show();
? ? ? ? ? ? }
? ? ? ? });
? ? }
}
原文鏈接:https://blog.csdn.net/wj778/article/details/106162102
相關推薦
- 2022-07-13 Android Canvas - StaticLayout 繪制多行文字
- 2022-06-02 使用kubeadm命令行工具創建kubernetes集群_云和虛擬化
- 2022-06-12 Python多線程的使用詳情_python
- 2023-04-18 Python之split函數的深入理解_python
- 2022-08-02 C#?HttpClient?Post參數同時上傳文件的實現_C#教程
- 2021-12-15 vscode?ssh安裝librosa處理音頻的解決方法_其它綜合
- 2022-09-30 C#?wpf?Grid中實現控件拖動調整大小的示例代碼_C#教程
- 2023-12-14 如何查看瀏覽器內核版本
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支