編輯:關於Android編程
android:isIndicator="false":設置是否為指示器,true表示不可與用戶交互 android:rating="":默認的評分數 android:stepSize="":步長(點擊一次增長的長度) android:numStars="":表示星星的數量,超出顯示范圍是他會以最大數量顯示,然後把星星分成numStars/stepSize份 style="?android:ratingBarStyleSmall|?android:ratingBarStyleIndicator|?android:ratingBarStyle":風格
//設置是否為指示器模式,及不可交互 ratingBar1.setIsIndicator(false); //設置評分條的最大范圍 ratingBar1.setMax(20); //設置星星數量 ratingBar1.setNumStars(10); //設置當前等級 ratingBar1.setRating(1); //設置步長 ratingBar1.setStepSize(1); //獲取星星數量 int num = ratingBar.getNumStars(); //獲取步長 float step = ratingBar.getStepSize(); //獲取當前評分,與參數rating一致 float currentRating = ratingBar.getRating();
package com.example.ratingbar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.widget.RatingBar; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private RatingBar ratingBar,ratingBar1; private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化控件 ratingBar = (RatingBar) findViewById(R.id.ratingBar); ratingBar1 = (RatingBar) findViewById(R.id.ratingBar1); textView = (TextView) findViewById(R.id.textView); //ratingbar的常用方法 //設置是否為指示器模式,及不可交互 ratingBar1.setIsIndicator(false); //設置評分條的最大范圍 ratingBar1.setMax(20); //設置星星數量 ratingBar1.setNumStars(10); //設置當前等級 ratingBar1.setRating(1); //設置步長 ratingBar1.setStepSize(1); //設置監聽器 ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { //獲取星星數量 int num = ratingBar.getNumStars(); //獲取步長 float step = ratingBar.getStepSize(); //獲取當前評分,與參數rating一致 // float currentRating = ratingBar.getRating(); Log.d("debug","num="+num+",step="+step+",rating="+rating); textView.setText(""+rating); } }); } }
package com.example.ratingbar; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.RatingBar; import android.widget.TextView; import android.widget.Toast; public class SecondActivity extends AppCompatActivity { private RatingBar ratingBar,ratingBar1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); //初始化控件 ratingBar = (RatingBar) findViewById(R.id.ratingBar); //設置監聽器 ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { Toast.makeText(SecondActivity.this,"點擊了RatingBar",Toast.LENGTH_SHORT).show(); } }); } }
先讓大家看看效果圖吧,相信很多Android初學者都想知道這中效果是怎麼實現的,來上圖: 想實現上面這張圖中的自定義加載樣式,其實很簡單,首先我們需要的布局組件有Proc
一.Android四大組件Android四大組件是Activity, Service, Content Provider,Broadcast Receiver。Activ
Android基礎入門教程——2.4.6 ListView的數據更新問題標簽(空格分隔): Android基礎入門教程本節引言: 我們前面已經學習
1,首先需要保證自己的jdk安裝配置完成http://www.eclipse.org/babel/downloads.php 2 sdk的下載,http:/