目录结构

1、res/layout/rating_bar_layout.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <ProgressBar android:id="@+id/progressBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:progress="10" style="@android:style/Widget.ProgressBar.Horizontal" mce_style="@android:style/Widget.ProgressBar.Horizontal" /> <RatingBar android:id="@+id/ratingBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:max="5" android:rating="0.5" /> </LinearLayout>

2、src/com/taofu5/RatingBarActivity.java

package com.taofu5; import android.app.Activity; import android.os.Bundle; import android.widget.ProgressBar; import android.widget.RatingBar; public class RatingBarActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.rating_bar_layout); RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar); ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float progress, boolean fromUser) { ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar); progressBar.setProgress((int)(ratingBar.getRating()*100/5)); } }); } }

3、AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.taofu5" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".RatingBarActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="7" /> </manifest>

效果图:

更多相关文章

  1. Android存储使用参考
  2. android自定义ProgressBar
  3. Android(安卓)ListActivity实现遍历文件列表,查看文档类文件
  4. Ubuntu 10.10 编译Android(安卓)2.2
  5. 二.Android项目结构
  6. Android屏幕元素层次结构
  7. 64位Ubuntu配置android环境报错(...adb": error=2, 没有那个文件
  8. android 中的getCacheDir()、getFilesDir()、getExternalFilesDi
  9. 目录

随机推荐

  1. 对android应用一些破解的方法
  2. android hello world on xiaomi 1
  3. android系统下使用openGL开发demo
  4. Android NotificationChannel
  5. Android onTouch事件解析
  6. Edittext在xml文件中设置android:focusabl
  7. iOS与Android的对比
  8. Android中Failed to 。。。。。。timeout
  9. 【经验记录】Android上传文件到服务器
  10. Android:Deprecated Thread methods are