Activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".MainActivity" >
<RatingBar
android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="3"
android:stepSize="0.2" />
<TextView
android:id="@+id/ratetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Now Rate : 3" />
<RatingBar
android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:rating="2" />
<RatingBar
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="4"
android:rating="2.5" />
<RatingBar
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="10"
android:rating="7" />
</LinearLayout>
MainActivity.java
package com.example.ratingbarex01;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.RatingBar;
import android.widget.TextView;
public class MainActivity extends Activity {
RatingBar mRating;
TextView mRateText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRating = (RatingBar) findViewById(R.id.ratingbar);
mRateText = (TextView) findViewById(R.id.ratetext);
mRating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
mRateText.setText("Now Rate : " + rating);
}
});
}
@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;
}
}
'Android' 카테고리의 다른 글
날짜와 시간 - DatePickerDialog,TimePickerDialog (0) | 2013.04.02 |
---|---|
날짜와 시간 - DatePicker (0) | 2013.04.02 |
시크바(SeekBar) (0) | 2013.04.02 |
프로그레스 바 (ProgressBar) 실습2 (0) | 2013.04.02 |
프로그레스 바 (ProgressBar) 실습 (0) | 2013.04.02 |