优化了自定义RatingBar可以在xml中设置每次点击走半星还是一星性能并修复了一些bug
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -27,5 +27,5 @@
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
@@ -20,6 +20,7 @@
|
||||
app:starFill="@mipmap/star_yellow"
|
||||
app:starHalf="@mipmap/star_half_yellow"
|
||||
app:starImageSize="30dp"
|
||||
app:stepSize="Half"
|
||||
app:starStep="4.5"></com.kejiang.yuandl.view.RatingBar>
|
||||
|
||||
<com.ldd.pullview.AbPullToRefreshView
|
||||
|
||||
@@ -31,6 +31,7 @@ public class RatingBar extends LinearLayout {
|
||||
private Drawable starEmptyDrawable;
|
||||
private Drawable starFillDrawable;
|
||||
private Drawable starHalfDrawable;
|
||||
private final StepSize stepSize;
|
||||
|
||||
public void setStarHalfDrawable(Drawable starHalfDrawable) {
|
||||
this.starHalfDrawable = starHalfDrawable;
|
||||
@@ -68,11 +69,13 @@ public class RatingBar extends LinearLayout {
|
||||
TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.RatingBar);
|
||||
starImageSize = mTypedArray.getDimension(R.styleable.RatingBar_starImageSize, 20);
|
||||
starStep = mTypedArray.getFloat(R.styleable.RatingBar_starStep, 1.0f);
|
||||
stepSize = StepSize.fromStep(mTypedArray.getInt(R.styleable.RatingBar_stepSize, 1));
|
||||
starCount = mTypedArray.getInteger(R.styleable.RatingBar_starCount, 5);
|
||||
starEmptyDrawable = mTypedArray.getDrawable(R.styleable.RatingBar_starEmpty);
|
||||
starFillDrawable = mTypedArray.getDrawable(R.styleable.RatingBar_starFill);
|
||||
starHalfDrawable = mTypedArray.getDrawable(R.styleable.RatingBar_starHalf);
|
||||
mClickable = mTypedArray.getBoolean(R.styleable.RatingBar_clickable, true);
|
||||
mTypedArray.recycle();
|
||||
for (int i = 0; i < starCount; ++i) {
|
||||
final ImageView imageView = getStarImageView(context, attrs);
|
||||
imageView.setImageDrawable(starEmptyDrawable);
|
||||
@@ -95,6 +98,9 @@ public class RatingBar extends LinearLayout {
|
||||
if (indexOfChild(v) > fint) {
|
||||
setStar(indexOfChild(v) + 1);
|
||||
} else if (indexOfChild(v) == fint) {
|
||||
if(stepSize==StepSize.Full){
|
||||
return;
|
||||
}
|
||||
if (imageView.getDrawable().getCurrent().getConstantState().equals(starHalfDrawable.getConstantState())) {
|
||||
setStar(indexOfChild(v) + 1);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.kejiang.yuandl.view;
|
||||
|
||||
/**
|
||||
* Created by yuandl on 2016/8/2 0002.
|
||||
*/
|
||||
public enum StepSize {
|
||||
Half(0), Full(1);
|
||||
int step;
|
||||
|
||||
StepSize(int step) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
static StepSize fromStep(int step) {
|
||||
for (StepSize f : values()) {
|
||||
if (f.step == step) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
@@ -39,8 +39,8 @@
|
||||
<declare-styleable name="Dialog">
|
||||
<attr name="DialogTitleAppearance" format="reference" />
|
||||
<attr name="DialogTitleText" format="reference|string" />
|
||||
<attr name="DialogSpotColor" format="reference|color"/>
|
||||
<attr name="DialogSpotCount" format="integer"/>
|
||||
<attr name="DialogSpotColor" format="reference|color" />
|
||||
<attr name="DialogSpotCount" format="integer" />
|
||||
</declare-styleable>
|
||||
<declare-styleable name="RichText">
|
||||
<attr name="placeHolder" format="reference" />
|
||||
@@ -65,23 +65,33 @@
|
||||
<attr name="border_width" format="dimension" />
|
||||
<attr name="border_color" format="color" />
|
||||
</declare-styleable>
|
||||
<declare-styleable name="RatingBar" >
|
||||
<declare-styleable name="RatingBar">
|
||||
<!--尺寸值-->
|
||||
<attr name="starImageSize" format="dimension"/>
|
||||
<attr name="starCount" format="integer"/>
|
||||
<!--资源文件值-->
|
||||
<attr name="starEmpty" format="reference"/>
|
||||
<!--资源文件值-->
|
||||
<attr name="starFill" format="reference"/>
|
||||
<!--资源文件值-->
|
||||
<attr name="starHalf" format="reference"/>
|
||||
<!--boolean值-->
|
||||
<attr name="clickable" format="boolean"/>
|
||||
<attr name="starImageSize" format="dimension" />
|
||||
<!--星星总数-->
|
||||
<attr name="starCount" format="integer" />
|
||||
<!--空白的星星资源文件值-->
|
||||
<attr name="starEmpty" format="reference" />
|
||||
<!--满星资源文件值-->
|
||||
<attr name="starFill" format="reference" />
|
||||
<!--半星资源文件值-->
|
||||
<attr name="starHalf" format="reference" />
|
||||
<!--是否可点击boolean值-->
|
||||
<attr name="clickable" format="boolean" />
|
||||
<!--当前进度float值-->
|
||||
<attr name="starStep" format="float"/>
|
||||
<attr name="starStep" format="float" />
|
||||
<!--每次进度float值-->
|
||||
<attr name="stepSize">
|
||||
<enum name="Half" value="0" />
|
||||
<enum name="Full" value="1" />
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
|
||||
|
||||
<declare-styleable name="isHalfStar">
|
||||
<attr name="language">
|
||||
<enum name="English" value="1" />
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
<declare-styleable name="AutoTabLayout">
|
||||
<attr name="auto_textSize_base_width" format="boolean"></attr>
|
||||
</declare-styleable>
|
||||
@@ -89,13 +99,13 @@
|
||||
|
||||
<declare-styleable name="SlideDetailsLayout">
|
||||
<!-- float value for indicate the moment of switch panel-->
|
||||
<attr name="percent" format="float"/>
|
||||
<attr name="percent" format="float" />
|
||||
<!-- how long the animation keep-->
|
||||
<attr name="duration" format="integer"/>
|
||||
<attr name="duration" format="integer" />
|
||||
<!-- default panel to show after init-->
|
||||
<attr name="default_panel" format="enum">
|
||||
<enum name="front" value="0"/>
|
||||
<enum name="behind" value="1"/>
|
||||
<enum name="front" value="0" />
|
||||
<enum name="behind" value="1" />
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user