首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RatingBar不可点击

RatingBar不可点击
EN

Stack Overflow用户
提问于 2016-05-01 14:36:40
回答 2查看 1.1K关注 0票数 1

我正在尝试在我的应用程序中添加一个评分栏,以便人们可以对问题对象进行评分。

下面是我的XML版本的评分栏:

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="Question: "
            android:textSize="20sp"
            android:gravity="center"/>

        <EditText
            android:id="@+id/fragment_question_string"
            android:layout_width="0sp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:hint="New question"/>

    </LinearLayout>

    <RatingBar
        android:id="@+id/fragment_question_rating_bar"
        style="@style/Base.Widget.AppCompat.RatingBar.Small"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"/>

</LinearLayout>

下面是我在代码片段的onCreateView(LayoutInflater,View,Bundle)方法中使用RatingBar的那部分代码

代码语言:javascript
复制
RatingBar mRatingBar = (RatingBar) v.findViewById(R.id.fragment_question_rating_bar);
mRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            int r = (int) rating;

            try {
                mQuestion.rateQuestion(r);
            } catch (IllegalRatingValue illegalRatingValue) {
                illegalRatingValue.printStackTrace();
            }
        }
    });

问题是评级栏是无法点击的。当我尝试给问题打分时,它不会改变星级的数量。它看起来就像一个图像,因为它不会对触摸做出反应。我该如何解决这个问题?

EN

回答 2

Stack Overflow用户

发布于 2016-05-01 15:30:01

我已经使用了这些步骤来获取用户的评级。

在xml中

代码语言:javascript
复制
       <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize=".5"
        android:layout_gravity="center_vertical"
        android:progressTint="@color/grey"
        android:progressBackgroundTint="@color/grey"
        android:secondaryProgressTint="@color/grey"
        android:rating="0.0" />

在活动中

RatingBar ratingBar=(RatingBar)findViewById(R.id.ratingBar);

浮动额定值= ratingBar.getRating();

票数 1
EN

Stack Overflow用户

发布于 2018-10-25 00:46:25

尽管您的代码没有反映这个问题,但这个问题有时可能是由android:isIndicator="true"引起的。对于希望用户能够更改评等的任何情况,请删除此条目。

将指示器显式设置为true意味着用户将无法更改它。即使您已经实现了new RatingBar.OnRatingBarChangedListener()onRatingChanged()方法也不会触发。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36963827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档