场景

效果

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

将布局改为LinearLayout,并通过android:orientation="vertical">设置为垂直布局,然后添加一个RatingBar,并通过

android:rating=""

设置其星数为5

然后再添加一个Button,分别给他们添加Id。

<?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://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".RatingBarActivity"> <RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating=""
/> <Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF5000"
android:text="发表评价"
/> </LinearLayout>

然后来到Activity,通过Id获取RatingBar和Button,在button的点击事件中,获取星级数,并提示。

packagecom.badao.relativelayouttest;

importandroidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
importandroid.widget.Toast; public class RatingBarActivity extends AppCompatActivity {
private RatingBarratingBar; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating_bar);
ratingBar = (RatingBar) findViewById(R.id.ratingBar);
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
float rating = ratingBar.getRating();
Toast.makeText(RatingBarActivity.this,"你的评分为:"+rating+"分",Toast.LENGTH_SHORT).show();;
}
});
}
}

Android中点击按钮获取星级评分条的评分的更多相关文章

  1. Android中点击按钮获取string.xml中内容并弹窗提示

    场景 AndroidStudio跑起来第一个App时新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797 ...

  2. Android中点击按钮启动另一个Activity以及Activity之间传值

    场景 点击第一个Activity中的按钮,启动第二个Activity,关闭第二个Activity,返回到第一个Activity. 在第一个Activity中给第二个Activity传递值,第二个Act ...

  3. Android中点击隐藏软键盘最佳方法——Android开发之路4

    Android中点击隐藏软键盘最佳方法 实现功能:点击EditText,软键盘出现并且不会隐藏,点击或者触摸EditText以外的其他任何区域,软键盘被隐藏: 1.重写dispatchTouchEve ...

  4. Android 中点击返回键弹出“在按一次退出程序”的做法

    在很多应用中都有这种做法,连续点击两次才退出程序,目的是为了防止用户不小心点击到了返回键而退出程序了,添加了一次用户确认的过程. 其实做法很简单,只需要做一个延时的消息处理就可以了. 首先在我们在一个 ...

  5. 微信小程序开发——点击按钮获取用户授权没反应或反应很慢的解决方法

    异常描述: 点击按钮获取用户手机号码,有的时候会出现点击无反应或很久之后才弹出用户授权获取手机号码的弹窗,这种情况下,也会出现点击穿透的问题(详见:微信小程序开发——连续快速点击按钮调用小程序api返 ...

  6. Android点击按钮拨打电话

    代码改变世界 Android点击按钮拨打电话 public void callPhone(String str) { Intent intent=new Intent(); intent.setAct ...

  7. Android中点击事件的四种写法详解

    Android中点击事件的四种写法 使用内部类实现点击事件 使用匿名内部类实现点击事件 让MainActivity实现View.OnClickListener接口 通过布局文件中控件的属性 第一种方法 ...

  8. 使用Android点击按钮跳转页面

    1.首先新建一个Android工程,命名为MyApp(名字可以自己随意起); 2.以原有的MainActivity.java文件为登录界面,然后在src文件中的包上面右击选择New目录下的Other中 ...

  9. Py3+PyQt5+Eric6:学习记录之第一天:点击按钮获取文本框的值并输出。

    一.使用qt designer拖拽界面. 使用qtdesigner拖拽界面:

随机推荐

  1. 大叔 EF 来分析 EntityFrameworks.Data.Core 2

    Extensions 1DbCommand拦截器扩展DbCommandInterceptorExtensions 2Class for IQuerable extensions methods Inc ...

  2. 团队项目-Beta冲刺1(七个小矮人)

    团队项目-Beta冲刺1(七个小矮人) 一.格式描述 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScien ...

  3. Python3中的super()函数详解

    关于Python3中的super()函数 我们都知道,在Python3中子类在继承父类的时候,当子类中的方法与父类中的方法重名时,子类中的方法会覆盖父类中的方法, 那么,如果我们想实现同时调用父类和子 ...

  4. Client API Object Model - Grid Context(3.3)

    Grids 网格,以表格的形式显示数据, 网格可以跨越整个form,也可以是form中的一项. 被称为子网格(subgrid). grid有两种, 一种是read-only grid, 另一种是edi ...

  5. 【原创】(一)Linux进程调度器-基础

    背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...

  6. (初学JS)JS基础——ATM机终端程序编写<1.0>

    初步学习了JS基础,为了更好地将所学知识熟练运用,我进行了银行ATM存取款机的模拟程序编写,主要通过VScode终端实现系列操作. 我的ATM程序包括6个主要功能:1.查询余额 2.存钱 3. 取钱 ...

  7. http--->http缓存机制系统梳理

    http缓存 HTTP请求的过程 从在浏览器地址栏敲入域名-DNS解析-实际IP-(中间可能多个代理服务器分发)- 源服务器,请求抵达源服务器后,在服务器上找到请求的资源,再通过代理服务器一层层的返回 ...

  8. python之路:day3

    内容 变量的创建过程 身份运算和None 数据类型 一. 变量创建过程 首先,当我们定义了一个变量name = ‘oldboy’的时候,在内存中其实是做了这样一件事: 程序开辟了一块内存空间,将‘ol ...

  9. C# 解析JSON遇到以错误提示:应为状态“Element”。。遇到名称为“”、命名空间为“”的“Text”。

    话不多说:仔细看代码: ①json格式错误导致报错 {"TeachIQ":"  语言  0小时0分钟  未完成","Temperature" ...

  10. Marginalize

    在David M.Blei 的Distance Dependent Chinese Restaurant Processes 中提到:DDCRP 的一个重要性质,也是和dependent DP 的一个 ...