简体   繁体   中英

Android ratingbar with tablelayout

I am using TableLayout in my application with 4 columns. When I insert a rating bar in a row, with layout_span=3 , the stars are not working as expected.

For Example, I gave numStars=5 , but it is showing 2/3 of 6th star. Also if I click on 3rd star, it selects 3.25 stars, if select 4th, 4.5 is highlighted and so on ... the scaling is not working properly.

I tried changing layout_height to wrap_content, but same result. Only if I delete layout_span, then it works fine, but in that case my columns of other rows have distortion.

Can anyone please help me regarding what is the issue? And if this is the normal behavior, then how can I get proper rating bar with layout_span?

<TableRow
            android:layout_width="wrap_content"
            android:layout_height="0dp"
        android:layout_weight="1" >

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

        <RatingBar
                android:id="@+id/add_rating"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_span="3"
                android:numStars="5"
                android:stepSize="1"
                android:rating="4" />

    </TableRow>
// NORMAL ROW
<TableRow
            android:id="@+id/tr12"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
        android:layout_weight="1" >
            <TextView
                android:id="@+id/lab_datepurchased"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/datepurchased" />

            <EditText
                android:id="@+id/add_datepurchased"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="@string/dateinput" />

            <TextView
                android:id="@+id/lab_shelfno"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/shelfno" />

            <EditText
                android:id="@+id/add_shelfno"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="@string/definputtext2" />

        </TableRow>
// try this
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/banner_holder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center">

        <TextView
            android:id="@+id/rating"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="rating" />

        <RatingBar
            android:id="@+id/add_rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:stepSize="1"
            android:rating="4" />
    </TableRow>

    <TableRow
        android:id="@+id/tr12"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center">
        <TextView
            android:id="@+id/lab_datepurchased"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:text="@string/datepurchased" />

        <EditText
            android:id="@+id/add_datepurchased"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="@string/dateinput" />

        <TextView
            android:id="@+id/lab_shelfno"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:text="@string/shelfno" />

        <EditText
            android:id="@+id/add_shelfno"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="@string/definputtext2" />

    </TableRow>
</TableLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM