android之RatingBar控件用法详解

android之RatingBar控件用法详解,第1张

概述MainActivity.javapackagecom.example.mars_2500_ratingbar;importandroid.support.v7.app.ActionBarActivity;

MainActivity.java

package com.example.mars_2500_ratingbar;import androID.support.v7.app.ActionBaractivity;import androID.support.v7.app.Actionbar;import androID.support.v4.app.Fragment;import androID.app.Activity;import androID.os.Bundle;import androID.util.Log;import androID.vIEw.LayoutInflater;import androID.vIEw.Menu;import androID.vIEw.MenuItem;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.vIEw.VIEwGroup;import androID.Widget.button;import androID.Widget.ratingbar;import androID.Widget.ratingbar.Onratingbarchangelistener;import androID.os.Build;public class MainActivity extends Activity{  ratingbar ratingbar;  button button1;  public static String TAG="MainActivity";  @OverrIDe  protected voID onCreate(Bundle savedInstanceState)  {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    ratingbar=(ratingbar)findVIEwByID(R.ID.ratingbar1);    ratingbar.setonratingbarchangelistener(new ratingbarchangelistener());    button1=(button)findVIEwByID(R.ID.buttn1);    button1.setonClickListener(new ClickListener());      }  class ratingbarchangelistener implements Onratingbarchangelistener  {    @OverrIDe    public voID onratingChanged(ratingbar ratingbar,float rating,boolean fromUser)    {      Log.i(TAG,"当前分数="+rating);      System.out.println("当前分数="+rating);    }  }    class ClickListener implements OnClickListener  {    @OverrIDe    public voID onClick(VIEw v)    {  //在当前加0.5分      ratingbar.setrating(ratingbar.getrating()+0.5f);    }  }      @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;  }}

activity_main.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="fill_parent"     > <ratingbar     androID:ID="@+ID/ratingbar1"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:numStars="5"    androID:stepSize="0.5"    />  <button     androID:ID="@+ID/buttn1"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_below="@ID/ratingbar1"    androID:text="评分"     /> </linearLayout>

以上就是小编为大家带来的androID之ratingbar控件用法详解的全部内容了,希望对大家有所帮助,多多支持编程小技巧~

总结

以上是内存溢出为你收集整理的android之RatingBar控件用法详解全部内容,希望文章能够帮你解决android之RatingBar控件用法详解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1148063.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存