android之RatingBar控件用法详解

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控件用法详解的全部内容了,希望对大家有所帮助,多多支持我们~

(0)

相关推荐

  • Android UI控件RatingBar实现自定义星星评分效果

    本文实例为大家分享了Android RatingBar星星评分效果的具体代码,供大家参考,具体内容如下 继承关系 AppCompatRatingBar 效果图 xml <RatingBar style="@android:style/Widget.DeviceDefault.RatingBar.Small" android:layout_width="wrap_content" android:layout_height="wrap_content&

  • Android控件之RatingBar自定义星级评分样式

    一.RatingBar简单介绍 RatingBar是基于SeekBar(拖动条)和ProgressBar(状态条)的扩展,用星形来显示等级评定,在使用默认RatingBar时,用户可以通过触摸/拖动/按键(比如遥控器)来设置评分, RatingBar自带有两种模式 ,一个小风格 ratingBarStyleSmall,大风格为ratingBarStyleIndicator,大的只适合做指示,不适用与用户交互. 效果图展示: 二.实例 1.布局文件 <?xml version="1.0&qu

  • Android自定义View之自定义评价打分控件RatingBar实现自定义星星大小和间距

    在Android开发中,我们经常会用到对商家或者商品的评价,运用星星进行打分.然而在Android系统中自带的打分控件,RatingBar特别不好用,间距和大小无法改变.所以,我就自定义了一个特别好用的打分控件.在项目中可以直接使用,特别简单.下面直接上图: 效果图 实现原理 其实就是自定义View继承LinearLayout ,然后里面动态加了五个ImageView. 实现代码,有详细的注释 在attrs中声明的可以在xml中设置的变量 <declare-styleable name="

  • Android星级评分条控件RatingBar使用详解

    Android开发中,时不时的就有要实现星星的评分效果,比如某宝,某团,相信大家也都见过,当然了我们可以自己去画,也可以用美工给切的图去实现,其实在Android原生的控件中就可以来实现这样的效果,它就是RatingBar. 来,我们先看一张图(只在代码中引入了控件) 实现效果如下图: 我们先看一下它的继承关系:这玩意和SeekBar的类结构是一样的,也是ProgressBar的子类 相关属性: android:isIndicator:是否用作指示,用户无法更改,默认false android:

  • Android App中使用RatingBar实现星级打分功能的教程

    RatingBar简单介绍 RatingBar是基于SeekBar(拖动条)和ProgressBar(状态条)的扩展,用星形来显示等级评定,在使用默认RatingBar时,用户可以通过触摸/拖动/按键(比如遥控器)来设置评分, RatingBar自带有两种模式 ,一个小风格 ratingBarStyleSmall,大风格为ratingBarStyleIndicator,大的只适合做指示,不适用与用户交互. 自定义RatingBar需要注意的地方 一般情况下,系统自带的RatingBar是远远无法

  • Android评分控件RatingBar使用实例解析

    无论游戏,应用,网站,都少不了评分控件.在Android SDK 中提供了 RatingBar控件来实现相应的工作. <RatingBar/>标签有几个常用评分相关属性 android:numStars,指定评分五角星数. android:rating,指定当前分数 android:stepSize, 指定分数增量 <RatingBar/>还有3种 常用的style属性 默认style 就是ratingBarStyle style ratingBarStyleIndicator 不

  • Android RatingBar星星评分控件实例代码

    效果图: 直接上代码: xml文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http:

  • Android中SeekBar和RatingBar用法实例分析

    本文实例讲述了Android中SeekBar和RatingBar用法.分享给大家供大家参考,具体如下: 什么是SeekBar? 可以拖动的进度条(在播放器中使用最常见) 1.在布局文件中声明 <SeekBar android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/seekBar" /> 2.定义一个OnSeekB

  • Android自定义控件RatingBar调整字体大小

    项目需要,做一个可以调整字体大小的控件,能在滑动或点击时改变选中的位置,效果图如下: 这是一个类似于RatingBar的控件,然而配置RatingBar的样式难以实现这样的效果,如选中的图案和上面的文字对齐.因此,有必要写一个自定义View来实现. 思路如下: 新建一个TextRatingBar继承View类 在onDraw()方法中绘制元素:文字.横线.短竖线和圆形标记 重写onMeasure()方法,控制整体大小和边界 在onTouchEvent()方法中处理ACTION_DOWN和ACTI

  • android之RatingBar控件用法详解

    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之SeekBar控件用法详解

    MainActivity.java package com.example.mars_2400_seekbar; 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 a

  • Android实现在列表List中显示半透明小窗体效果的控件用法详解

    本文实例讲述了Android实现在列表List中显示半透明小窗体效果的控件用法.分享给大家供大家参考,具体如下: Android 在列表List中显示半透明小窗体效果的控件,多的不多直接上代码,要说的都在注释里了: import com.hiapk.market.R; import android.content.Context; import android.graphics.PixelFormat; import android.os.Handler; import android.view

  • Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解

    本文实例讲述了Python GUI编程学习笔记之tkinter中messagebox.filedialog控件用法.分享给大家供大家参考,具体如下: 相关内容: messagebox 介绍 使用 filedialog 介绍 使用 首发时间:2018-03-04 22:18 messagebox: 介绍:messagebox是tkinter中的消息框.对话框 使用: 导入模块:import tkinter.messagebox 选择消息框的模式: 提示消息框:[返回"ok"] tkint

  • Android评分RationBar控件使用详解

    Android评分RationBar控件,供大家参考,具体内容如下 主要是不想用太多三方的控件,所以决定尽可能自己写,最近有写一个评分的页面,废话不多说直接上图 我觉得嘛 这个东西用ViewGroup包起来感觉会写很多View 于是我决定使用之定义控件 直接上代码 /** * 评论专用星星 * <p> * 宽高都不能用wrap_content 必须使用固定值或者match_parent * <p> * MIXED : 在控件的宽度范围内等分星星 * <p> * SCRO

  • Android日期选择控件使用详解

    本文实例为大家分享了Android日期选择控件的使用方法,供大家参考,具体内容如下 1.创建dialog 布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" an

  • ASP.NET中Label控件用法详解

    Label 控件提供了一种在 ASP.NET 网页中以编程方式设置文本的方法.当希望在运行时更改网页中的文本(比如响应按钮单击)时,通常可以使用 Label 控件. 一.属性 Label控件的常用属性及说明如表1所示. 表1 Label控件常用属性及说明 属性 说明 ID 控件的ID名称 Text 控件显示的文本 Width 控件的宽度 Visible 控件是否可见 CssClass 控件呈现的样式 BackColor 控件的背景颜色 Enabled 控件是否可用 下面详细介绍Label控件的一

  • Android滚轮选择时间控件使用详解

    滚轮选择控件 Android自带的选择时间控件有点丑,往往产品和设计都比较嫌弃,希望做成ios一样的滚轮选择,下面是我在NumberPicker的基础上自定义的选择控件,效果如下: 原理 基于NumberPicker实现 动态填充数值 联动 接口监听回调 实现滚轮效果有github上mark比较多的WheelView,但是阅读源码发现数据是一次性填入的,选择时间的话,填入10年就是10*365=3650条数据,也就是new出三千多个TextView,想想都觉得恐怖,肯定是不行的,于是便想到用Nu

  • Android自定义日历控件实例详解

    为什么要自定义控件 有时,原生控件不能满足我们对于外观和功能的需求,这时候可以自定义控件来定制外观或功能:有时,原生控件可以通过复杂的编码实现想要的功能,这时候可以自定义控件来提高代码的可复用性. 如何自定义控件 下面我通过我在github上开源的Android-CalendarView项目为例,来介绍一下自定义控件的方法.该项目中自定义的控件类名是CalendarView.这个自定义控件覆盖了一些自定义控件时常需要重写的一些方法. 构造函数 为了支持本控件既能使用xml布局文件声明,也可在ja

  • Android 仿淘宝、京东商品详情页向上拖动查看图文详情控件DEMO详解

    一.淘宝商品详情页效果 我们的效果 二.实现思路 使用两个scrollView,两个scrollView 竖直排列,通过自定义viewGroup来控制两个scrollView的竖直排列,以及滑动事件的处理.如下图 三.具体实现 1.继承viewGroup自定义布局View 重写onMeasure()和onLayout方法,在onLayout方法中完成对两个子ScrollView的竖直排列布局,代码如下: 布局文件: <RelativeLayout xmlns:android="http:/

随机推荐