gpt4 book ai didi

android - 自定义评级栏仅显示一颗星

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:08:10 25 4
gpt4 key购买 nike

enter image description here .

我创建了一个自定义评级栏。我设置了 5 个自定义星图,但它只显示了一个。而不是可变数量的评级可绘制对象,我只看到一个,无论设置的星星数量如何。任何帮助将不胜感激。

xml.code :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<RatingBar
android:id="@+id/ratingbar_default"
style="@style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp" />

<TextView
android:id="@+id/textView"
android:layout_width="276dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="show state up checkbox"
android:textColor="#CC00CC"
android:textSize="20dp" />

Java 代码:

Activity RatingBarActivity

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating);

final TextView text = (TextView) findViewById(R.id.textView);

final RatingBar ratingBar_default = (RatingBar) findViewById(R.id.ratingbar_default);

ratingBar_default.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener()
{
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser)
{
// TODO Auto-generated method stub
text.setText("Rating: " + String.valueOf(rating));
}
});

<?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_ratingbar_full_empty" />
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/star_ratingbar_full_empty" />
<item
android:id="@android:id/progress"
android:drawable="@drawable/star_ratingbar_full_filled" />
</layer-list>

res/drawable/star_ratingbar_full_empty.xml:

<?xml version="1.0" encoding="utf-8"?>

<selector
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/star2" />

<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/star2" />

<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/star2" />

<item android:drawable="@drawable/star2" />

</selector>

res/drawabstar_ratingbar_full_filled.xml:

<?xml version="1.0" encoding="utf-8"?>

<!-- This is the rating bar drawable that is used to
show a unfilled cookie. -->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/star3" />

<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/star1" />

<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/star1" />

<item android:drawable="@drawable/star1" />

</selector>

styles.xml 文件:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></style>

<style name="RatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/star_rating_bar_full</item>
<item name="android:minHeight">48dip</item>
<item name="android:maxHeight">48dip</item>
</style>

</resources>

最佳答案

在我的案例中,问题出在图层列表中的 SVG 可绘制对象中。当我将它们更改为 PNG 时,它开始正常工作

关于android - 自定义评级栏仅显示一颗星,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30144452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com