码迷,mamicode.com
首页 > 移动开发 > 详细

安卓学习第23课——ratingBar

时间:2014-08-25 19:09:44      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   color   os   io   ar   div   

progressBar这部分相对而言比较简单

<LinearLayout 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:orientation="vertical">
  <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:src="@drawable/lijiang" />
    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:numStars="5"
        android:progress="255"
        android:stepSize="0.5" />
</LinearLayout>
package com.example.ratingbar;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;

public class MainActivity extends Activity {

    ImageView image;
    RatingBar ratingBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        image=(ImageView) findViewById(R.id.image);
        ratingBar=(RatingBar) findViewById(R.id.ratingBar);
        ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){

            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating,
                    boolean fromUser) {
                image.setImageAlpha((int) (rating*255/5));
                
            }
            
        });
    }
}

 

安卓学习第23课——ratingBar

标签:android   style   blog   http   color   os   io   ar   div   

原文地址:http://www.cnblogs.com/Yvettey-me/p/3935573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!