簡體   English   中英

Android評級欄與表格布局

[英]Android ratingbar with tablelayout

我在具有4列的應用程序中使用TableLayout。 當我以layout_span=3連續插入評級欄時,星星無法正常工作。

例如,我給出了numStars=5 ,但它顯示了6星的2/3 同樣,如果我單擊第三顆星,它會選擇3.25顆星,如果選擇第四顆,則會突出顯示4.5顆,依此類推...縮放比例無法正常工作。

我嘗試將layout_height更改為wrap_content,但結果相同。 僅當我刪除layout_span時,它才能正常工作,但在這種情況下,我其他行的列會變形。

有人可以幫助我解決什么問題嗎? 如果這是正常現象,那么如何使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM