展会信息港展会大全

Android RatingBar评分案例(图)
来源:互联网   发布日期:2015-10-03 11:14:37   浏览:2181次  

导读:Android RatingBar评分案例?xml version=1.0 encoding=utf-8?LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical ......

Android RatingBar评分案例

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:paddingLeft="10dip"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<RatingBar

android:id="@+id/rbOne"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:numStars="3"

android:rating="2.5" />

<RatingBar android:id="@+id/rbTwo"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:numStars="5"

android:rating="2.25" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dip">

<TextView android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<RatingBar android:id="@+id/rbThree"

style="?android:attr/ratingBarStyleSmall"

android:layout_marginLeft="5dip"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical" />

</LinearLayout>

<RatingBar

android:id="@+id/rbFour"

style="?android:attr/ratingBarStyleIndicator"

android:layout_marginLeft="5dip"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical" />

</LinearLayout>

package com.test;

import android.app.Activity;

import android.os.Bundle;

import android.util.Log;

import android.widget.RatingBar;

import android.widget.RatingBar.OnRatingBarChangeListener;

import android.widget.TextView;

public class RatingBarDemo_2 extends Activity implements OnRatingBarChangeListener{

private RatingBar smallRatingBar = null;

private RatingBar indicatorRatingBar = null;

private TextView ratingText = null;

private RatingBarrabarone,rabartwoBar;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.ratingbar_2);

ratingText = (TextView) findViewById(R.id.textView);

indicatorRatingBar = (RatingBar) findViewById(R.id.rbFour);

smallRatingBar = (RatingBar) findViewById(R.id.rbThree);

// The different rating bars in the layout. Assign the listener to us.

rabarone=((RatingBar)findViewById(R.id.rbOne));

rabarone.setOnRatingBarChangeListener(this);

rabartwoBar=((RatingBar)findViewById(R.id.rbTwo));

rabartwoBar.setOnRatingBarChangeListener(this);

}

@Override

public void onRatingChanged(RatingBar ratingBar, float rating,

boolean fromUser) {

// getNumStars

// Returns the number of stars shown.

final int numStars = ratingBar.getNumStars();

ratingText.setText(" 欢迎程度 " + rating + "/" + numStars);

if (indicatorRatingBar.getNumStars() != numStars)

{

indicatorRatingBar.setNumStars(numStars);

smallRatingBar.setNumStars(numStars);

}

// getRating

// Gets the current rating 评级(number of stars filled).

if (indicatorRatingBar.getRating() != rating)

{

Log.d("sxp","rating " + rating);

indicatorRatingBar.setRating(rating);

smallRatingBar.setRating(rating);

}

// getStepSize

// Gets the step size of this rating bar.

final float ratingBarStepSize = ratingBar.getStepSize();

if (indicatorRatingBar.getStepSize() != ratingBarStepSize)

{

Log.d("sxp","ratingBarStepSize " + ratingBarStepSize);

indicatorRatingBar.setStepSize(ratingBarStepSize);

smallRatingBar.setStepSize(ratingBarStepSize);

}

}

}

执行效果:

赞助本站

人工智能实验室

相关热词: RatingBar 评分

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港