今天试手ListView,编了个类似打分的东东,但是编好之后却发现其中的ratingbar的星星数量不受控制,设置了星星数量为5,结果却是一长串的。
xml布局和效果图如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text="TextView"
android:textSize="25dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:text="TextView" />
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:numStars="5"
style="?android:attr/ratingBarStyleSmall"
android:layout_toRightOf="@+id/textView2" />
<!-- -->
</RelativeLayout>
</LinearLayout>
效果图成了这样子:
出来的完全不是想要的5颗星,问题出在哪里呢?找了半天,发现ratingbar也没有什么特别需要设置的地方,想破脑袋,最后发现是由于ratingbar的两边都被限制了, android:layout_toRightOf="@+id/textView2" android:layout_alignParentRight="true" ,这样再去控制星星数量就不行了,只能控制其大小了,将布局文件中的android:layout_toRightOf="@+id/textView2" 一句去掉,终于正常了,,也算是个收获最后效果如下:
挺简单的东东,高手勿喷