gpt4 book ai didi

android - 评分栏在 gridview 中显示黑色叠加层

转载 作者:行者123 更新时间:2023-11-30 01:23:59 29 4
gpt4 key购买 nike

我试图在我的 gridview 行中显示评级栏,但评级栏顶部始终有一个黑色覆盖层。如果我的 GridView 只有 1 行,那么评级栏显示得非常好。但是当我的 gridview 中有多行时,评分栏顶部总是有一个黑色覆盖层。那么我该如何解决这个问题呢?而且它似乎只发生在 Lollipop 设备上。我的代码如下:

我的 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>

还有我的 Adapter 中的 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

1 行的 GridView

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>

最佳答案

试试这个,

<?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>

关于android - 评分栏在 gridview 中显示黑色叠加层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36693632/

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