2017-06-16 30 views
2

我有一個RatingBar內的相對佈局:如何在ListView中設計RatingBar? (API 21中的問題和低)

所有好的,灰色和金色的星星。 https://www.dropbox.com/s/22y8117fwyv969x/Stars23.JPG?dl=0

但是,如果我有一個ListView裏面相同的RatingBar結果是:

問題是什麼?我該如何解決它?有任何想法嗎?

代碼:

<RatingBar 
    android:id="@+id/ratings_list_item_ratingBar" 
    style="@style/Widget.AppCompat.RatingBar.Small" 
    android:theme="@style/RatingBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:isIndicator="true" 
    android:numStars="5" 
    android:stepSize="1"/> 

風格styles.xml:

<style name="RatingBar" parent="Theme.AppCompat"> 
    <item name="colorControlNormal">@android:color/darker_gray</item> 
    <item name="colorControlActivated">@color/Yelow200</item> 
</style> 

適配器:

public View getView(int position, View convertView, ViewGroup parent) { 
      LayoutInflater inflater = (LayoutInflater) context 
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View rowView = inflater 
          .inflate(R.layout.ratings_list_item, parent, false); 
      RatingBar ratingBar = (RatingBar) rowView.findViewById(R.id.ratings_list_item_ratingBar); 
      float ratingNumber = (float)values.get(position).getRating(); 
      ratingBar.setRating(ratingNumber); 
      return rowView; 
    } 
+0

爲您的項目有其他風格,V19和樣式,V21? –

+0

如果您使用的是ListView,那麼您是否有一個實現getView()方法的適配器?如果是這樣,請分享代碼 – 0X0nosugar

+0

@ 0X0nosugar更新了適配器,但我不更改適配器上的樣式 – Ivan

回答

0

LayoutInflater您正在使用可能不會考慮你的應用程序的樣式通知。 XML。使用以下LayoutInflater

嘗試(抱歉,沒有之前測試這種方式,但它幫助類似的情況):

LayoutInflater inflater = LayoutInflater.from(parent.getContext());

+0

你是一個富有天才的人。非常感謝:)解決了 – Ivan