在android中自定义评分栏
我必须设计一个自定义列表项,其中包括评级栏
我遵循本教程([android 中自定义评级栏的问题)用于自定义和调整评级栏大小。评级栏现在显示很小,但我无法单击它。
我的自定义列表项代码是:
<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>
屏幕截图是:
编辑:
我开发了自定义评级栏,但现在无论我在横向和查看时设置评级在纵向应用程序中,整个评级栏被取消选择。如何保持评级栏处于选中状态?
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 :
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
较小的 RatingBar 样式 ( ratingBarStyleSmall) 和较大的仅指示符样式 ( ratingBarStyleIndicator) 不支持用户交互,只能用作指示符。
(来自 RatingBar 手册)
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)
对
HDPI
和MDPI
使用不同尺寸的可绘制对象,然后为您的评级栏指定一个以dp
为单位的特定高度。或者,在可绘制对象中放置一行空像素。但第二种方法只是解决了评级栏的外观,并且高度是错误的。我建议第一种方式。Use drawables with different sizes for
HDPI
andMDPI
, and then give your ratingbar a specific height indp
. 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.