最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android星級評分條實現(xiàn)評分界面

 更新時間:2022年05月17日 17:26:53   作者:wj778  
這篇文章主要為大家詳細介紹了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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

松桃| 慈利县| 巴里| 湘西| 西昌市| 陈巴尔虎旗| 包头市| 牙克石市| 分宜县| 长海县| 舞钢市| 通河县| 河源市| 温泉县| 青岛市| 和平区| 论坛| 辽宁省| 金华市| 镇巴县| 遂昌县| 疏勒县| 平阳县| 红原县| 梅河口市| 文山县| 辽中县| 陆川县| 彭泽县| 崇左市| 盘山县| 青州市| 平顶山市| 东丽区| 河津市| 宁海县| 安庆市| 霍山县| 寻乌县| 广水市| 塔城市|