3

I have to design a custon list item including rating bar in it

I followed this tutorial([Problem with custom rating bar in android) for customising and resizing rating bar.Rating bar is now appering small bt i am unable to click on it

My custom listItem Code is :

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:stretchColumns="*" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/tbl">
    <TableRow>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:src="@drawable/icon" />
            <TextView android:layout_width="wrap_content" android:id="@+id/txt"
                android:layout_height="wrap_content" android:text="Item Name" />
        </LinearLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView android:layout_width="100dp" android:gravity="center"
                android:layout_height="wrap_content" android:text="Price" />
            <TextView android:layout_width="100dp" android:gravity="center"
                android:layout_height="wrap_content" android:text="Discount" />
            <TextView android:layout_width="100dp" android:gravity="center"
                android:layout_height="wrap_content" android:text="In Stock" />
        </LinearLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <!-- <RatingBar android:id="@+id/ratingBar1" android:fitsSystemWindows="false" 
                android:maxWidth="150dip" android:minHeight="23dip" android:maxHeight="25dip" 
                android:layout_height="40dp" android:layout_width="150dp" /> -->
            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="Shipping days" />
            <RatingBar android:id="@+id/ratingBar" style="?android:attr/ratingBarStyleSmall"
                android:layout_gravity="center_vertical|center_horizontal"
                android:focusable="true" android:layout_width="wrap_content"
                android:layout_height="wrap_content"></RatingBar>
            <Button android:layout_width="60dip" android:layout_height="35dip"
                android:text="Buy" android:textSize="15dip"/>
        </LinearLayout>
    </TableRow>
</TableLayout>

And the screenShot is : enter image description here

EDIT :

i developed the customized rating bar but now whatever i set the rating in landscape and when i look at the application in portrait whole rating bars are deselected..what to do to keep rating bar selected ?

Community
  • 1
  • 1
Shruti
  • 1
  • 13
  • 55
  • 95
  • 2
    The rating bar with style `style="?android:attr/ratingBarStyleSmall" ` is not user intractable. Have a look at [Pretty RatingBar](http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/) – Adil Soomro Oct 01 '11 at 07:45
  • Thanx Adil Soomro.That tutorial is awesome ,customized my rating bar :) – Shruti Oct 01 '11 at 08:48
  • @AdilSoomro agree with Adil, its not user interactable. – Paresh Mayani Oct 01 '11 at 08:53
  • Have a look at this post : http://stackoverflow.com/questions/5800657/how-to-create-custom-ratings-bar-in-android/5800686#14327733 – Jerome VDL Jan 14 '13 at 22:15

2 Answers2

3

The smaller RatingBar style ( ratingBarStyleSmall) and the larger indicator-only style (ratingBarStyleIndicator) do not support user interaction and should only be used as indicators. (from RatingBar manual)

1

Use drawables with different sizes for HDPI and MDPI, and then give your ratingbar a specific height in dp. Or, put one empty row of pixels in your drawable. but the second way just solves the look of your ratingbars, and the height will be wrong. I suggest the first way.

Kayhan Asghari
  • 2,817
  • 1
  • 28
  • 47