2017-08-10 71 views
0

更新:当我将其更改为ConstraintLayout而不是RelativeLayout时,我更容易调整星星并使其正确。但我仍然想知道在ReletiveLayout中是否有一种方法可以调整。任何想法?android studio:调整ratingBar明星位置

我正在使用android studio制作带有ratingBar的APP。现在我的问题是,无论我如何调整ratingBar的位置,它都无法在虚拟机或实际设备上正确显示。例如,当它是完整的,并在XML设计页面在中间,在设备上最右边的明星中最右边的角落被切断一点点,像下面的图片显示:

rightmost corner is cut a little bit

我的代码调整ratingBar布局是这样的:

<RatingBar 
    android:id="@+id/ratingBar1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:numStars="7" 
    android:scaleX="0.7" 
    android:scaleY="0.7" 
    android:stepSize="1" 
    app:layout_constraintBottom_toBottomOf="@id/button3" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    android:layout_below="@+id/imageView" 
    android:layout_centerHorizontal="true" /> 

我不知道问题出在哪里,有人有想法吗?

呵呵,另外一个信息是,这个ratingBar是设计在标签活动的一个片段页面上的,而这个页面布局是RelativeLayout,这有什么关系吗?

在此先感谢!

+0

先给一个'静width'你' RatingBar“,因为这是一个问题,如果您将宽度设置为wrap_content,则会削减RatingBar并使用android:max =”7“来显示最大星号 –

回答

0

我在AS中试过了你的xml代码,它的工作正常。将它置于线性或相对没有任何区别。但是,如果您遇到问题,请尝试将layout_widthwrap_content更改为match_parent

+0

大多数时间使缓存失效并重新启动'是用于java代码和构建错误,但你也可以尝试。 – deejay

0

您可以尝试使用此lib目录下:

编译 'com.github.techery:properratingbar:0.0.5'

<io.techery.properratingbar.ProperRatingBar 
     android:id="@+id/reviewRatingBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="@dimen/v30dp" 
     android:textSize="@dimen/v32sp" 
     app:prb_defaultRating="0" 
     app:prb_symbolicTick="★" 
     app:prb_tickSpacing="@dimen/v5dp" 
     app:prb_tickNormalDrawable="@drawable/star_inactive" 
     app:prb_tickSelectedDrawable="@drawable/star_active" 
     app:prb_totalTicks="5" 
     android:stepSize="1" 
     app:prb_clickable="true" />