Android RatingBar星星評分控件實(shí)例代碼
效果圖:

直接上代碼:
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.example.blogtest.MainActivity">
<!--numStars設(shè)置星星的數(shù)量,stepSize默認(rèn)的評分-->
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb_main_rating"
android:numStars="5"
android:stepSize="0.5"
/>
</LinearLayout>
Java代碼:
package com.example.blogtest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.RatingBar;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private RatingBar rb_main_rating;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//獲得RatingBar的控件
rb_main_rating = (RatingBar) findViewById(R.id.rb_main_rating);
//給控件設(shè)置監(jiān)聽事件
rb_main_rating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Toast t=Toast.makeText(MainActivity.this,"您的評分為:"+rating,Toast.LENGTH_SHORT);
t.setGravity(Gravity.CENTER,0,0);
t.show();
}
});
}
}
以上所述是小編給大家介紹的Android RatingBar 評分控件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Android 對手機(jī)網(wǎng)絡(luò)的檢測和監(jiān)聽的方法示例
本篇文章主要介紹了Android 對手機(jī)網(wǎng)絡(luò)的檢測和監(jiān)聽的方法示例,主要使用BroadcastReceiver廣播接收器來接收網(wǎng)絡(luò)狀態(tài),現(xiàn)在分享給大家,也給大家做個(gè)參考,有興趣的一起來了解一下2018-03-03
Android Toolbar自定義標(biāo)題標(biāo)題居中的實(shí)例代碼
這篇文章主要介紹了Android Toolbar自定義標(biāo)題 標(biāo)題居中的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-08-08
淺析Kotlin使用infix函數(shù)構(gòu)建可讀語法流程講解
這篇文章主要介紹了淺析Kotlin使用infix函數(shù)構(gòu)建可讀語法,我們在Kotlin中就多次使用A to B這樣的語法結(jié)構(gòu)構(gòu)建鍵值對,包括Kotlin自帶的mapOf()函數(shù),這種語法結(jié)構(gòu)的優(yōu)點(diǎn)是可讀性強(qiáng)2023-01-01
Android編程之文件讀寫操作與技巧總結(jié)【經(jīng)典收藏】
這篇文章主要介紹了Android編程之文件讀寫操作與技巧,結(jié)合實(shí)例形式總結(jié)分析了Android常見的文件與目錄的讀寫操作,及相關(guān)函數(shù)的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
Android實(shí)現(xiàn)可使用自定義透明Dialog樣式的Activity完整實(shí)例
這篇文章主要介紹了Android實(shí)現(xiàn)可使用自定義透明Dialog樣式的Activity,結(jié)合完整實(shí)例形式分析了Android Activity自定義style的操作步驟與相關(guān)技巧,需要的朋友可以參考下2016-07-07
Android開發(fā)之資源文件用法實(shí)例總結(jié)
這篇文章主要介紹了Android開發(fā)之資源文件用法,結(jié)合實(shí)例形式總結(jié)分析了Android開發(fā)過程中針對資源文件的常見操作技巧,需要的朋友可以參考下2016-02-02
Android邊框裁切的正確姿勢實(shí)現(xiàn)示例
這篇文章主要為大家介紹了Android邊框裁切的正確姿勢實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
Android實(shí)現(xiàn)原生鎖屏頁面音樂控制
這篇文章主要介紹了Android實(shí)現(xiàn)原生鎖屏頁面音樂控制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12

