1. SeekBar的主要属性
2. OnSeekBarChangeListener
3. RatingBar的主要属性
4. OnRatingBarChangeListener
1. SeekBar的主要属性
2. OnSeekBarChangeListener
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingBottom="@dimen/activity_vertical_margin" 6 android:paddingLeft="@dimen/activity_horizontal_margin" 7 android:paddingRight="@dimen/activity_horizontal_margin" 8 android:paddingTop="@dimen/activity_vertical_margin" 9 tools:context="first.pack.MainActivity$PlaceholderFragment" > 10 11 <SeekBar 12 android:id="@+id/firstSeekbar" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:max="100" 16 /> 17 18 </RelativeLayout>
1 public static class PlaceholderFragment extends Fragment { 2 3 private SeekBar seekBar; 4 5 public PlaceholderFragment() { 6 } 7 8 @Override 9 public View onCreateView(LayoutInflater inflater, ViewGroup container, 10 Bundle savedInstanceState) { 11 View rootView = inflater.inflate(R.layout.fragment_main, container, false); 12 13 seekBar = (SeekBar)rootView.findViewById(R.id.firstSeekbar); 14 seekBar.setProgress(30); 15 16 SeekBarListener seekBarListener = new SeekBarListener(); 17 seekBar.setOnSeekBarChangeListener(seekBarListener); 18 19 return rootView; 20 } 21 22 class SeekBarListener implements OnSeekBarChangeListener{ 23 24 @Override 25 public void onProgressChanged(SeekBar seekBar, int progress, 26 boolean fromUser) { 27 // TODO Auto-generated method stub 28 //seekBar当前进度条改变的那个seekBar 29 //progress当前的进度 30 //fromUser是否是用户手动拖动进度条 31 Log.i("tag","Progress:" + progress + "; fromUser:" + fromUser); 32 } 33 34 @Override 35 public void onStartTrackingTouch(SeekBar seekBar) { 36 // TODO Auto-generated method stub 37 Log.i("tag","OnStart"); //开始拖动就会触发 38 } 39 40 @Override 41 public void onStopTrackingTouch(SeekBar seekBar) { 42 // TODO Auto-generated method stub 43 Log.i("tag","OnStop"); //结束拖动就会触发 44 } 45 46 } 47 }
3. RatingBar的主要属性
4. OnRatingBarChangeListener
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingBottom="@dimen/activity_vertical_margin" 6 android:paddingLeft="@dimen/activity_horizontal_margin" 7 android:paddingRight="@dimen/activity_horizontal_margin" 8 android:paddingTop="@dimen/activity_vertical_margin" 9 tools:context="first.pack.MainActivity$PlaceholderFragment" > 10 11 <RatingBar 12 android:layout_width="wrap_content" //不可使用match_parent,否则显示不对 13 android:layout_height="wrap_content" 14 android:numStars="5" //5颗星星 15 android:stepSize="0.5" //step=0.5颗星 16 /> 17 18 </RelativeLayout>