2016-04-18 42 views
1

我想在我的gridview行中顯示評級欄,但總是在評級欄上有一個黑色覆蓋。如果我只有一排我的網格視圖,那麼評分欄顯示得非常好。但是,當我在gridview中有多行時,總是在評級欄頂部有一個黑色覆蓋。那麼我如何解決這個問題呢?它似乎只發生在棒棒糖設備上。Ratingbar在gridview中顯示黑色覆蓋

我的GridView:我下面的代碼給出

<UI.ExpandableHeightGridView 
       android:id="@+id/gridview_agent_reviews" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="5dp" 
       android:horizontalSpacing="2dp" 
       android:isScrollContainer="false" 
       android:numColumns="1" 
       android:stretchMode="columnWidth" /> 

我的GridView行:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="0.5dp" 
    android:layout_marginBottom="5dp" 
    android:background="#cccccc" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" 
    android:layout_marginTop="5dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/img_review_flag" 
     android:layout_toStartOf="@+id/img_review_flag" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/lbl_review_date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="5dp" 
      android:layout_marginRight="5dp" 
      android:text="2016-04-05" 
      android:typeface="sans" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="5dp" 
      android:layout_marginRight="5dp" 
      android:text="|" 
      android:typeface="sans" /> 

     <TextView 
      android:id="@+id/lbl_review_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="5dp" 
      android:layout_marginRight="5dp" 
      android:text="Recommendation by John Doe" 
      android:typeface="sans" /> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/img_review_flag" 
     android:layout_width="22dp" 
     android:layout_height="22dp" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="5dp" 
     android:src="@drawable/ic_flag_blue" /> 
</RelativeLayout> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="0.5dp" 
    android:layout_marginBottom="5dp" 
    android:layout_marginTop="5dp" 
    android:background="#cccccc" /> 

<RatingBar 
    android:id="@+id/rate_review" 
    style="@style/CustomRatingBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:isIndicator="true" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="0.5dp" 
    android:layout_marginBottom="5dp" 
    android:layout_marginTop="5dp" 
    android:background="#cccccc" /> 

<TextView 
    android:id="@+id/lbl_review_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Congrats! Keep up the great work." 
    android:textColor="#000" 
    android:typeface="sans" /> 

</LinearLayout> 

而我在我的適配器getView:

@Override 
public View getView(int i, View view, ViewGroup viewGroup) { 
    View v = view; 
    ViewHolder holder; 
    try { 

     if (v == null) { 
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = inflater.inflate(R.layout.row_list_agent_review, null); 
      holder = new ViewHolder(); 
      holder.lblReviewDate = (TextView) v.findViewById(R.id.lbl_review_date); 
      holder.lblReviewer = (TextView) v.findViewById(R.id.lbl_review_name); 
      holder.lblReviewDesc = (TextView) v.findViewById(R.id.lbl_review_text); 
      holder.ReviewRate = (RatingBar) v.findViewById(R.id.rate_review); 
      v.setTag(holder); 

     } else { 
      holder = (ViewHolder) v.getTag(); 
     } 

     String []Date=list.get(i).CreateDate.split("T"); 
     holder.lblReviewDate.setText(Date[0]); 
     holder.lblReviewer.setText("Recommendation by "+list.get(i).FirstName+" "+list.get(i).LastName); 
     holder.lblReviewDesc.setText(list.get(i).RecommendationInfo); 
     holder.ReviewRate.setRating(Float.valueOf(list.get(i).RatingScale)); 

    }catch (Exception e){ 


    } 

    return v; 
} 

和的截圖問題:

GridView控件與多行

GridView with multiple rows

GridView控件與1行

GridView with 1 row

編輯

我的風格的xml:

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

ratingbarcustom.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/rating_bar_empty" /> 
<item android:id="@android:id/secondaryProgress" 
    android:drawable="@drawable/rating_bar_empty" /> 
<item android:id="@android:id/progress" 
    android:drawable="@drawable/rating_bar_filled" /> 
</layer-list> 

ratingbarempty.xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/star_outline" android:state_pressed="true" android:state_window_focused="true"/> 
<item android:drawable="@drawable/star_outline" android:state_focused="true" android:state_window_focused="true"/> 
<item android:drawable="@drawable/star_outline" android:state_selected="true" android:state_window_focused="true"/> 
<item android:drawable="@drawable/star_outline"/> 
</selector> 

ratingbarfull.xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/star_full" android:state_pressed="true"  android:state_window_focused="true"/> 
<item android:drawable="@drawable/star_full" android:state_focused="true" android:state_window_focused="true"/> 
<item android:drawable="@drawable/star_full" android:state_selected="true" android:state_window_focused="true"/> 
<item android:drawable="@drawable/star_full"/> 
</selector> 
+0

請分享您的style.xml –

+0

@PradeepGupta我已更新我的問題。請看一下。 –

+0

不需要使用選擇器進行選擇並取消選擇評級欄。你必須在ratingbarcustom.xml中設置你的圖像 –

回答

1

試試這個,

<?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_outline" /> 
<item android:id="@android:id/secondaryProgress" 
    android:drawable="@drawable/star_outline" /> 
<item android:id="@android:id/progress" 
    android:drawable="@drawable/star_full" /> 
</layer-list> 
+1

沒有工作。我的評級欄中仍有多行黑色疊加。順便說一句我已經測試了gentmotion模擬器的API級別16和評分欄顯示完美。但在真實設備上有黑色覆蓋。 –