2017-08-10 121 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" />