简体   繁体   English

在android中自定义评级栏

[英]Customizing rating bar in android

I have to design a custon list item including rating bar in it 我必须设计一个包含评级栏的custon列表项

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 我按照这个教程([ android中的自定义评级栏的问题 )进行自定义和调整评级栏的大小。现在正在调整小条,我无法点击它

My custom listItem Code is : 我的自定义listItem代码是:

<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 : 而screenShot是: 在此输入图像描述

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 ? 我开发了定制的评级栏,但现在无论我在景观中设置评级,当我在纵向查看应用程序时,取消选择整个评级栏...如何保持评级栏被选中?

The smaller RatingBar style ( ratingBarStyleSmall) and the larger indicator-only style (ratingBarStyleIndicator) do not support user interaction and should only be used as indicators. 较小的RatingBar样式(ratingBarStyleSmall)和较大的仅指示器样式(ratingBarStyleIndicator)不支持用户交互,只应用作指标。 (from RatingBar manual ) (来自RatingBar手册

Use drawables with different sizes for HDPI and MDPI , and then give your ratingbar a specific height in dp . 使用不同大小的drawable用于HDPIMDPI ,然后以dpHDPI给出您的评级栏特定高度。 Or, put one empty row of pixels in your drawable. 或者,在drawable中放置一行空像素。 but the second way just solves the look of your ratingbars, and the height will be wrong. 但第二种方式只是解决了你的评级栏的外观,而高度将是错误的。 I suggest the first way. 我建议第一种方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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