나는 5 가지 색상을 가질 수 있으며 별 아래에 점이있는 사각형 막대가있는 사용자 정의 RatingBar를 만들었습니다.진저 브레드 장치의 사용자 정의 평가판
내가 장소의 몇이보기를 사용하고 모든 것이 4.0 이상 안드로이드 괜찮 : 여기처럼 보이는 방법이다. 하지만 진저 브레드에는 몇 가지 문제가 있습니다.
public class KrinsenRating extends RelativeLayout {
private TextView mRanking;
private RatingBar mStars;
public KrinsenRating(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.krinsen_rating, this);
loadViews();
}
public KrinsenRating(Context context) {
super(context);
loadViews();
}
private void loadViews() {
mRanking = (TextView) findViewById(R.id.ranking_bar_position);
mStars = (RatingBar) findViewById(R.id.ranking_bar);
}
public void setRating(long rating){
RatingConverter rc = new RatingConverter(rating);
Bitmap bmp_empty = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_empty)).getBitmap();
Bitmap bmp_half = null;
Bitmap bmp_full = null;
switch (rc.getColor()) {
case 1:
bmp_half = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_half1)).getBitmap();
bmp_full = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_full1)).getBitmap();
mRanking.setBackgroundColor(getResources().getColor(R.color.ranking1));
break;
case 2:
bmp_half = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_half2)).getBitmap();
bmp_full = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_full2)).getBitmap();
mRanking.setBackgroundColor(getResources().getColor(R.color.ranking2));
break;
case 3:
bmp_half = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_half3)).getBitmap();
bmp_full = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_full3)).getBitmap();
mRanking.setBackgroundColor(getResources().getColor(R.color.ranking3));
break;
case 4:
bmp_half = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_half4)).getBitmap();
bmp_full = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_full4)).getBitmap();
mRanking.setBackgroundColor(getResources().getColor(R.color.ranking4));
break;
case 5:
bmp_half = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_half5)).getBitmap();
bmp_full = ((BitmapDrawable) getResources().getDrawable(R.drawable.star_full5)).getBitmap();
mRanking.setBackgroundColor(getResources().getColor(R.color.ranking5));
break;
}
mStars.setProgressDrawable(GUI.buildRatingBarDrawables(new Bitmap[]{bmp_empty, bmp_half, bmp_full}));
mStars.setRating(rc.getRealRating());
mRanking.setText(rating + "");
}
}
이 줄은 혼란 : 다음 뷰 클래스에 대한 코드 mStars.setProgressDrawable(GUI.buildRatingBarDrawables(new Bitmap[]{bmp_empty, bmp_half, bmp_full}));
그러나 나는 (하나의 신장 성이 표시되어) setProgressDrawable()
호출 후에 별 렌더링에 있기 때문에 문제의이 있어야했다.
public static Drawable buildRatingBarDrawables(Bitmap[] images) {
final int[] requiredIds = { android.R.id.background,
android.R.id.secondaryProgress, android.R.id.progress };
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
Drawable[] pieces = new Drawable[3];
for (int i = 0; i < 3; i++) {
ShapeDrawable sd = new ShapeDrawable(new RoundRectShape(
roundedCorners, null, null));
BitmapShader bitmapShader = new BitmapShader(images[i],
Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
sd.getPaint().setShader(bitmapShader);
ClipDrawable cd = new ClipDrawable(sd, Gravity.LEFT,
ClipDrawable.HORIZONTAL);
if (i == 0) {
pieces[i] = sd;
} else {
pieces[i] = cd;
}
}
LayerDrawable ld = new LayerDrawable(pieces);
for (int i = 0; i < 3; i++) {
ld.setId(i, requiredIds[i]);
}
return ld;
}
그래서, 모든 안드로이드 ICS에 대한 확인 및 최신하지만 진저 브레드에 좀 이상한 상황이 : 여기 방법 buildRatingBarDrawables
입니다. 무엇보다도 진저 브레드에 모든 것이 괜찮습니다. 그러나 별이 전혀없는 경우가 종종 있습니다. 포인트가있는 사각형 막대는 항상 오른쪽이지만 별이 사라지는 경우가 있습니다.
당신이 볼 수있는 것처럼, 때로는 괜찮 때로는하지 않습니다 :/내 탐색 slidingMenu에이 등급 막대가 여기에 모든 단일 행에 평가 막대를 사용 ListView
에서 예제 화면입니다 거기에는 별이 천천히 슬라이드 할 때 표시되지만 슬라이드가 끝난 후에 (onOpened가 호출되어야하는 경우) 별이 사라집니다.
내가 평가 레이아웃 XML 파일을 추가 :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/avatar_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<RatingBar
android:id="@+id/ranking_bar"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:clickable="false"
android:focusable="false"
android:isIndicator="true"
android:numStars="3"
android:progressDrawable="@drawable/krinsen_rating"
android:stepSize="0.1" />
<TextView
android:id="@+id/ranking_bar_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ranking_bar"
android:layout_centerHorizontal="true"
android:contentDescription="@string/register_avatar"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="2dp"
android:textColor="@android:color/white"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
별이 사라지고, 한 당신은 함께 보았다 구성보기에서 계층 뷰어를 사용하여 상태를 볼 수 있습니다 (적절한 크기가있는 경우)? – Luksprog
다른 화면 크기의 생강 빵 장치를 사용해 보셨나요? 아마도 화면 크기 문제일까요? – user1634451