Android星级评分条实现评分界面
更新时间:2022年05月17日 17:26:53 作者:wj778
这篇文章主要为大家详细介绍了Android星级评分条实现评分界面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Android实现简单评分界面制作的具体代码,供大家参考,具体内容如下
简单评分界面的制作
实现如图界面
1.先布局,创建布局文件,使用相对布局,添加一个编辑框,一个文本框,一个评分条,再加一个按钮。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/etxt" android:layout_width="match_parent" android:layout_height="wrap_content" android:lines="5" android:hint="请评价店铺的服务态度与服务质量" android:textSize="20sp"/> <TextView android:id="@+id/txt" android:layout_below="@id/etxt" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="店铺评分" android:layout_marginTop="20dp" android:textSize="20sp"/> <RatingBar android:id="@+id/ratingbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/txt"//使用numStars=""来设置 android:stepSize="1"//设置每次一颗一颗增加 android:rating="5"//设置默认五颗星都是亮的 /> <Button android:id="@+id/btn" android:layout_below="@id/ratingbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@id/txt" android:text="发表评价"/> </RelativeLayout>
接下来在java代码当中实现对按钮监听
package com.example.relativelayout; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.RatingBar; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class RatingBar_Activity extends AppCompatActivity { private RatingBar ratingBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ratingbar_main); ratingBar=findViewById(R.id.ratingbar); Button btn=findViewById(R.id.btn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { float rating=ratingBar.getRating();//获取当前的星数 Toast.makeText(RatingBar_Activity.this,"你评价了"+rating+"颗星",Toast.LENGTH_LONG).show(); } }); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Android中使用socket使底层和framework通信的实现方法
native和framework的通信是通过jni,但是这一般只是framework调用native,native如果有消息要怎样通知上层 呢?android中GSP模块提供一种解决思路,但是实现有些复杂,这里介绍一种使用socket通信的方法可以使native和framework自由通信,感兴趣的朋友一起看看吧2016-11-11在android中ScrollView嵌套ScrollView解决方案
大家好,众所周知,android里两个相同方向的ScrollView是不能嵌套的,那要是有这样的需求怎么办,接下来为您介绍解决方法,感兴趣的朋友可以了解下2013-01-01Android 避免APP启动闪黑屏的解决办法(Theme和Style)
闪黑屏的原因主要是我们启动Activity的时候,需要跑完onCreate和onResume才会显示界面2013-07-07
最新评论