回答
編輯:這不是一個合適的答案,因爲OP想要自定義RatingBar
。但它仍然是一個解決方案。
這是可能的。你只要把五個鏡像資源中的每一個在你的項目,然後,做一個佈局是這樣的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="60dp"
android:layout_height="match_parent"
android:background="@android:color/black"
android:gravity="left"
android:orientation="vertical"
android:weightSum="5" >
<ImageView
android:id="@+id/oneStar"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/twoStars"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher"
android:visibility="visible" />
<ImageView
android:id="@+id/threeStars"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher"
android:visibility="visible" />
<ImageView
android:id="@+id/fourStars"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher"
android:visibility="visible" />
<ImageView
android:id="@+id/fiveStars"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher"
android:visibility="visible" />
把你的資源作爲ImageViews的來源。這應該是你的開始:D
我一直在想,但我也希望可以根據我的需要定製ratingbar。無論如何,謝謝你。 – TGIO
這不是正確的方法。你應該使用'RatingBar' –
偉大的教程here。
我會複製這個答案中的重要部分,以防鏈接無效。
首先,你應該創建它擴展了原有的RatingBar
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/food_ratingbar_full</item>
<item name="android:minHeight">48dip</item>
<item name="android:maxHeight">48dip</item>
</style>
</resources>
然後,你需要提供3個可繪製風格,爲什麼呢?因爲你應該填寫3個例子:空的,50%和全部。
這個文件是food_ratingbar_full.xml
<!-- This is the rating bar drawable that is used to
show a filled cookie. -->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/cookie" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/cookie" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/cookie" />
<item android:drawable="@drawable/cookie" />
</selector>
我只是用一個圖像的所有狀態(它實際上看起來像樣), 但是從選擇器中可以看到,有四個di不同的州 可能(@ drawable/cookie終於是一個真正的cookie png圖像)。 這裏很酷的事情是,RatingBar組件會自動根據需要在「完整」和 「空」圖像(如果您支持一半評級,如我的示例圖像中)時填寫部分Cookie。
然後使用你的風格,你應該在RatingBar XML中添加樣式屬性。
style="@style/foodRatingBar
問題是:如果需要,應該創建一個自定義樣式。您可以使用setRotation
來旋轉它。
設置視圖圍繞樞軸點旋轉的角度。增加值會導致順時針旋轉。
我已經讀過這個tut,但它不允許我使用1/5系統。因爲它只能使用1或2張圖片,其中1張爲全屏,2張爲第二張。但我需要使用1/5系統,例如3個5等等 – TGIO
- 1. 小風格自定義評級欄(只讀自定義評級欄)
- 2. Android自定義評級欄問題
- 3. 自定義評分欄?
- 4. 自定義Android評分欄拉伸圖像
- 5. 爲什麼自定義風格的評級欄錯誤膨脹?
- 6. 帶圖像的自定義工具欄
- 7. 如何在Android中創建自定義評級欄
- 8. 自定義UIProgressView與圖像
- 9. UISwitch與自定義圖像
- 10. UIActivity與自定義圖像
- 11. 自定義UIButton與圖像
- 12. 自定義標題欄與圖像視圖爲TabActivity
- 13. 自定義導航欄圖像6
- 14. 自定義圖像工具欄WTL
- 15. RatingBar自定義與每個評級元素的增加大小
- 16. 自定義導航欄與圖像背景
- 17. 影像圖與自定義圖標
- 18. 與圖像自定義列表視圖
- 19. Android自定義評分欄圖片大小問題
- 20. 自定義導航欄圖像周圍的白色像素
- 21. 自舉網格堆疊(評級欄)
- 22. 如何更改服務器的評級欄圖像
- 23. 自定義列表視圖/列表與Android搜索欄中的圖像
- 24. 系統圖標和圖像的自定義導航欄按鈕
- 25. 自定義圖像
- 26. xaml自定義進度條與圖像
- 27. 自定義按鈕與多個圖像
- 28. 單選按鈕與自定義圖像
- 29. 與Google+共享自定義圖像
- 30. Silverlight ProgressBar與自定義圖像磚
你想要你自定義評級欄在你的佈局? – joao2fast4u
在對話框中,但這並不重要imo – TGIO