Skip to content Skip to sidebar Skip to footer

How To Center A Ratingbar In Android

I have created a custom RatingBar as described in one of the tutorials given here on stack-overflow and it's looking great, the problem is with the centering of the image. here is

Solution 1:

Ok, I think I've got it.

The key issue is the ScrollView: it automatically makes things compact, unless you specifically tell it otherwise. In the scroll view, set

android:fillViewport="true"

to make it use the space available.

Solution 2:

Hello to get all items at top you have to put:

<TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:text="TextView" />

instead of:

  <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

if you just want the rating bar centred: just remove style="@style/starsRatingBar"

EDIT: forget any think I said befor, it seems to work better when I changed the style to : (adjust your min/max height to get "perfect result" )

<stylename="starsRatingBar"parent="@android:style/Widget.RatingBar"><itemname="android:progressDrawable">@android:drawable/star_on</item><itemname="android:minHeight">26dip</item><itemname="android:maxHeight">26dip</item></style>

Post a Comment for "How To Center A Ratingbar In Android"