我正在尝试在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 1行
修改
我的风格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 :(得分: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>