網站首頁 編程語言 正文
本文實例為大家分享了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-11-14 C#中對集合排序的三種方式_C#教程
- 2022-03-27 Android實現房貸計算器功能_Android
- 2023-03-18 Python?lambda匿名函數深入講解_python
- 2022-02-26 微信小程序 - 將頁面可分享到朋友圈功能(兩步完成)
- 2022-01-21 Shell編程:/bin/bash和/bin/sh的區別
- 2022-12-12 數組名不等于指針?sizeof()函數求數組大小錯誤問題及解決_C 語言
- 2022-01-18 移動端自適應布局(viewport+rem)
- 2023-01-26 Python+Sklearn實現異常檢測_python
- 最近更新
-
- 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同步修改后的遠程分支