編輯:關於Android編程
SeekBar 拖動條:拖動條和滾動條類似,當是拖動條可以拖動滑塊改變進度
RatingBar 星級評分條:星級評分條與拖動條相似
SeekBar特有的xml屬性
android:thumb 指定一個Arawable對象,作為之定義滑塊

RatingBar特有的xml屬性
android:isIndicator 是否允許用戶改變(true為不允許修改)
android:numStars 共有多少個星級
android:rating 默認的星級<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+YW5kcm9pZDpzdGVwU2l6ZSAgIMO/tM7WwcnZuMSx5Lbgydm49tDHvLY8YnI+CjwvcD4KPHA+PGltZyBzcmM9"/uploadfile/Collfiles/20140805/20140805091211121.png" alt="\">
為了知道改變的進度而做相應的操作,我們需要添加監聽
SeekBar 的監聽 OnSeekBarChangeListener
RatingBar的監聽 OnRatingBarChangeListener
下面我們通過實例來熟悉它們
(1)編寫布局文件 activity_main.xml
(2)編寫 MainActivity.java
package com.example.bar;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class MainActivity extends Activity {
private ImageView imgViewSB = null; //定義ImageView
private ImageView imgViewRB = null;
private SeekBar seekBar = null; //定義SeekBar
private RatingBar ratingBar = null; //定義RatingBar
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//布局組件
this.imgViewSB = (ImageView) findViewById(R.id.imgView1);
this.imgViewRB = (ImageView) findViewById(R.id.imgView2);
this.seekBar = (SeekBar) findViewById(R.id.seekBar);
this.ratingBar = (RatingBar) findViewById(R.id.reatingBar);
//seekBar設置監聽,改變圖片透明度
this.seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.i("onStopTrackingTouch", "停止拖動觸發的方法");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.i("onStartTrackingTouch", "開始拖動觸發的方法");
}
/**
* seekBar: SeekBar對象
* progress:拖動條的進度
* fromUser:是否用戶手動改變
*/
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
imgViewSB.setAlpha(progress); //設置圖片的透明度
Log.i("onProgressChanged", "拖動滑塊位置發生改變時觸發的方法");
}
});
//ratingBar設置監聽,改變圖片透明度
this.ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
/**
* ratingBar:RatingBar對象
* rating :星級的大小
* fromUser:是否用戶手動改變
*/
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
imgViewRB.setAlpha((int)(rating*255/5));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
允許之後,效果如下:

QQ火炬好友火炬排行榜怎麼看 你是第幾位火炬手呢
你是qq火炬手嗎?在這個騰訊QQ為巴西裡約奧運會推出的火炬傳遞活動中你是第幾位火炬手了呢?QQ火炬好友火炬排行榜怎麼看?下面小編就來教教你!QQ火炬好友火炬
Android錄制聲音文件(音頻)並播放
本文實例為大家分享了Android錄制音頻文件的具體代碼,供大家參考,具體內容如下1、這個demo中沒有對多次點擊同一個聲音文件做詳細處理,偶爾會有崩潰,用的時候需要注意
Android自定義ViewGroup之實現FlowLayout流式布局
整理總結自鴻洋的博客:http://blog.csdn.net/lmj623565791/article/details/38352503/ 一、FlowLay
android 游戲 實戰打飛機游戲 菜單頁面
目標 實現 控制 小飛機 左右移動 躲避子彈 打boss.本節 實現 開始菜單界面1 首先 資源文件拷過來2, 劃分游戲狀態 public static final