缩小评级栏大小时出现问题。

发布于 2024-11-27 05:45:13 字数 75 浏览 1 评论 0原文

我想减小评级栏的大小,我有一些样式属性可以做到这一点,但它们超出了用户交互的范围,它们只是指示器。所以,请告诉我如何缩小尺寸。提前致谢。

I want to reduce the size of the Rating bar, I got some style properties that do it, but they are out of the reach of user interaction they are just Indicator. So, please let me know how to reduce the size. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

薄凉少年不暖心 2024-12-04 05:45:13

如何粘合此处给出的代码 ...

第 1 步。您需要在 res/drawable ... 中添加自己的评级星星

A full star

Empty star

第 2 步 在 res/drawable 中,您需要 ratingstars .xml如下...

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+android:id/background"
          android:drawable="@drawable/star_empty" />
    <item android:id="@+android:id/secondaryProgress"
          android:drawable="@drawable/star_empty" />
    <item android:id="@+android:id/progress"
          android:drawable="@drawable/star" />
</layer-list>

第 3 步 在 res/values 中,您需要 styles.xml 如下 ...

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/ratingstars</item>
        <item name="android:minHeight">22dip</item>
        <item name="android:maxHeight">22dip</item>
    </style>
</resources>

Step- 4 在您的布局中...

<RatingBar 
      android:id="@+id/rtbProductRating"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:numStars="5"
      android:rating="3.5"
      android:isIndicator="false"
      style="@style/foodRatingBar"    
/>  

尝试 Activity ....

package x.y;

import android.app.Activity;
import android.os.Bundle;

public class RatingBarDemo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.product);

    }
}

使用此布局 product.xml ...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="5dip"
    android:paddingBottom="5dip">
    <ImageView
        android:id="@+id/imgProduct"
        android:layout_width="50dip"
        android:layout_height="50dip" 
        android:src="@drawable/icon" 
        android:scaleType="centerCrop"
        />
    <RelativeLayout
        android:id="@+id/layProductInfo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/imgProduct"
        android:paddingLeft="5dip"
        android:paddingRight="0dip"
        android:paddingTop="5dip"
        android:paddingBottom="5dip">  
        <TextView
            android:id="@+id/tvProductName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Product Name"
            android:textSize="17dip" 
            />
        <RatingBar 
            android:id="@+id/rtbProductRating"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:numStars="5"
            android:rating="3.5"
            android:isIndicator="false"
            style="@style/foodRatingBar"
            android:layout_below="@id/tvProductName"
            />  
        <TextView
            android:id="@+id/tvPriceLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="$45.87"
            android:layout_toRightOf="@id/rtbProductRating"
            android:layout_below="@id/tvProductName"
            android:paddingLeft="10dip"
            android:textSize="17dip" 
            />  
      </RelativeLayout>     
  </RelativeLayout>

How to glue the code given here ...

Step-1. You need your own rating stars in res/drawable ...

A full star

Empty star

Step-2 In res/drawable you need ratingstars.xml as follow ...

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+android:id/background"
          android:drawable="@drawable/star_empty" />
    <item android:id="@+android:id/secondaryProgress"
          android:drawable="@drawable/star_empty" />
    <item android:id="@+android:id/progress"
          android:drawable="@drawable/star" />
</layer-list>

Step-3 In res/values you need styles.xml as follow ...

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/ratingstars</item>
        <item name="android:minHeight">22dip</item>
        <item name="android:maxHeight">22dip</item>
    </style>
</resources>

Step-4 In your layout ...

<RatingBar 
      android:id="@+id/rtbProductRating"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:numStars="5"
      android:rating="3.5"
      android:isIndicator="false"
      style="@style/foodRatingBar"    
/>  

Try Activity ....

package x.y;

import android.app.Activity;
import android.os.Bundle;

public class RatingBarDemo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.product);

    }
}

With this layout product.xml ...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="5dip"
    android:paddingBottom="5dip">
    <ImageView
        android:id="@+id/imgProduct"
        android:layout_width="50dip"
        android:layout_height="50dip" 
        android:src="@drawable/icon" 
        android:scaleType="centerCrop"
        />
    <RelativeLayout
        android:id="@+id/layProductInfo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/imgProduct"
        android:paddingLeft="5dip"
        android:paddingRight="0dip"
        android:paddingTop="5dip"
        android:paddingBottom="5dip">  
        <TextView
            android:id="@+id/tvProductName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Product Name"
            android:textSize="17dip" 
            />
        <RatingBar 
            android:id="@+id/rtbProductRating"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:numStars="5"
            android:rating="3.5"
            android:isIndicator="false"
            style="@style/foodRatingBar"
            android:layout_below="@id/tvProductName"
            />  
        <TextView
            android:id="@+id/tvPriceLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="$45.87"
            android:layout_toRightOf="@id/rtbProductRating"
            android:layout_below="@id/tvProductName"
            android:paddingLeft="10dip"
            android:textSize="17dip" 
            />  
      </RelativeLayout>     
  </RelativeLayout>
小嗲 2024-12-04 05:45:13

我在这里搜索了很多有同样问题的帖子,我正在尝试 @Vaibhav A 提供的答案Jani,当我刚刚停下来解决这个问题时。我并不是说 @Vaibhav A. Jani 答案不正确。

试试这个,它对我来说可以看到小得多的星星:

RatingBar ratingBar = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);

而且我还能够动态创建大量的RatingBar,无需接触任何xml文件,只需java编码。

< em>参考

I've searched through a lot of posts with the same question here and I was trying out the answer provided by @Vaibhav A. Jani, when I just stopped by a more simple solution to this question. I am not saying that @Vaibhav A. Jani answer is not correct tho.

Try this, it worked for me to see stars much smaller:

RatingBar ratingBar = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);

And also I was able to create lots of RatingBar dynamically, without touching any xml file, just java coding.

Reference

很快妥协 2024-12-04 05:45:13

尝试改变风格

 <RatingBar
        android:layout_width="wrap_content"
        android:rating="4.5"
        style="@style/Base.Widget.AppCompat.RatingBar.Small"
        android:layout_height="wrap_content" />

Try changing style

 <RatingBar
        android:layout_width="wrap_content"
        android:rating="4.5"
        style="@style/Base.Widget.AppCompat.RatingBar.Small"
        android:layout_height="wrap_content" />
゛清羽墨安 2024-12-04 05:45:13

工作代码:
您可以轻松减小评级栏星星的大小
只需在xml中添加如下

android:scaleX="0.5" android:scaleY="0.5"

  <RatingBar
            android:id="@+id/ratingBar_visibility"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:numStars="5"
            android:scaleX="0.5"
            android:scaleY="0.5" />

Working Code :
You can easily reduce size of rating bar stars
Just add in xml as below

android:scaleX="0.5" android:scaleY="0.5"

  <RatingBar
            android:id="@+id/ratingBar_visibility"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:numStars="5"
            android:scaleX="0.5"
            android:scaleY="0.5" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文