我的申请有评分条。我想设置等级栏是不可点击和不可触摸的。为此,我在每个等级条的 xml文件中添加了以下代码。
xml
它在三星银河系的 Apollo GT-i5801上运行,但在 HTC 手机上却不能运行,为什么?
Xml 代码
android:clickable="false" android:focusableInTouchMode="false" android:focusable="false"
谢谢
Do not set enabled to false as this will dim the control. What you want to do is override the on touch listener like this:
import android.view.View.OnTouchListener; RatingBar ratingBar = (RatingBar)findViewById(R.id.ratingBar); ratingBar.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return true; } });
So basically you intercept the touch and do nothing with it
Also add the following code too to block trackball rollovers
ratingBar.setFocusable(false);
You could also set the RatingBar as indicator from the xml with the following:
android:isIndicator="true"
This is it write this code in your setOnRatingBarChangeListener
ratingaddrate.setIsIndicator(true);
Update :
You can use this example in your XML
also add this line to the Code
Add style="?android:attr/ratingBarStyleIndicator" into your layout For example
<RatingBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/review_star" style="?android:attr/ratingBarStyleIndicator" android:scaleX=".5" android:rating="3.5" android:scaleY=".5" android:transformPivotX="0dp" android:transformPivotY="0dp" android:max="5"/>