[英]Problem in reducing size of Rating Bar.
我想減少評級欄的大小,我得到了一些樣式屬性,但是它們不在用戶交互的范圍內,它們只是指標。 所以,請讓我知道如何減小尺寸。 提前致謝。
如何粘貼這里給出的代碼......
第1步。 您需要在res/drawable
擁有自己的評級星......
Step-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>
第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"
/>
嘗試活動....
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>
我在這里搜索了很多相同問題的帖子,我正在嘗試@Vaibhav A. Jani提供的答案,當時我剛剛通過一個更簡單的解決方案來解決這個問題。 我不是說@Vaibhav A. Jani的回答是不正確的。
試試這個,它讓我看到更小的星星:
RatingBar ratingBar = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
而且我還能夠動態創建大量的RatingBar,而不需要觸及任何xml文件,只需java編碼。
嘗試改變風格
<RatingBar
android:layout_width="wrap_content"
android:rating="4.5"
style="@style/Base.Widget.AppCompat.RatingBar.Small"
android:layout_height="wrap_content" />
工作代碼: 您可以輕松減小評級欄星的大小 只需添加xml如下
<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" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.