【问题标题】:RatingBar is unclickableRatingBar 不可点击
【发布时间】:2016-05-01 06:36:40
【问题描述】:

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

这是我的评分栏的 XML 版本:

<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 的代码部分

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();
            }
        }
    });

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

【问题讨论】:

    标签: java android onclick touch ratingbar


    【解决方案1】:

    我已使用这些步骤按用户评分。

    在xml中

           <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();

    【讨论】:

    • 对我不起作用!我不知道为什么,但 RatingBar 是不可点击的。我什至不能选择两/三颗星或任何东西
    【解决方案2】:

    虽然您的代码没有反映它,但这个问题有时可能是由 android:isIndicator="true" 引起的。如果您希望用户能够更改评级,请删除此条目。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-10
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多