<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.shumin.lbs06.MainActivity" >
<SeekBar
android:id="@+id/seekbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<RatingBar
android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/seekbar"
android:numStars="5"
android:progress="2"
android:stepSize="0.5" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ratingbar"
android:text="BUTTON"/>
</RelativeLayout>
package com.shumin.lbs06;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MainActivity extends ActionBarActivity {
private SeekBar seekbar;
private RatingBar ratingbar;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekbar=(SeekBar)findViewById(R.id.seekbar);
ratingbar=(RatingBar)findViewById(R.id.ratingbar);
button=(Button)findViewById(R.id.button);
seekbar.setProgress(15);
seekbar.setSecondaryProgress(18);
SeekBarListener seekBarListener=new SeekBarListener();
seekbar.setOnSeekBarChangeListener(seekBarListener);
RatingBarListener ratingbarlistener=new RatingBarListener();
ratingbar.setOnRatingBarChangeListener(ratingbarlistener);
ButtonListener buttonlistener=new ButtonListener();
button.setOnClickListener(buttonlistener);
}
class ButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
float i=ratingbar.getRating();
ratingbar.setRating(i+1);
}
}
class RatingBarListener implements OnRatingBarChangeListener{
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
System.out.println("星级"+rating+"是否来自用户"+fromUser);
}
}
class SeekBarListener implements OnSeekBarChangeListener{
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
System.out.println(progress+"进度"+fromUser);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
System.out.println("开始啦!!!");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
System.out.println("停下啦!!!");
}
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}