2017-09-18 1 views
1

viewpager 내에서 ratingbar를 만들었습니다. 페이지를 미끄러 뜨 렸을 때 문제가되지는 않았지만 미끄러지지 않으면 등급 표시가 보이지 않고 검정색과 파란색이되었습니다. 그런 다음 앱을 잠시 후에 그대로두면 앱이 닫힙니다.Android Ratingbar ViewPager에서 Lollipop 위에 잘못 렌더링 할 수 없습니다.

final int y =i; 
 
       nama[y] = new TextView(context); 
 
       nama[y].setLayoutParams(lhoriparams); 
 
       nama[y].setText(arrkonten.get(i)[0]); 
 

 

 
       rating[y] = new AppCompatRatingBar(context, null, android.R.attr.ratingBarStyleIndicator); 
 
       rating[y].setLayoutParams(ratingparams); 
 

 
       float f = Float.parseFloat(arrkonten.get(i)[1]); 
 
       rating[y].setRating(f); 
 

 
      
 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
 
       rating[y].setBackgroundTintList(ColorStateList.valueOf(Color.TRANSPARENT)); 
 
       rating[y].setSecondaryProgressTintList(ColorStateList.valueOf(Color.TRANSPARENT)); 
 
       rating[y].setProgressTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.blue))); 
 
       rating[y].setElevation(10); 
 
      } 
 

 
      //rating[y].setStepSize(1/10); 
 
       rating[y].setNumStars(5); 
 
       rating[y].setIsIndicator(true); 
 

 

 
       linfo[i].addView(nama[y]); 
 
       linfo[i].addView(rating[y]);

이, 들으 나를 도와주세요 :

when i am not slide it

when i slide it

는 코드입니다.

+0

시도를 사용하려고 . – marmor

+0

나는 color.TRANSPARENT을 다른 색깔로 바꿨다. 그러나 그것은 이전과 똑같다. – Enda

답변

0

마지막으로 앱에 RatingBar를 넣으려고 시도 할 때도 많은 문제가 있었지만 기기와 관련 있다고 생각합니다. 내 기기에서는 괜찮아 보이지만 표시되는 기기가 있으면 귀하의 스크린 샷과 유사합니다.

독자적으로 RatingBar를 만들었지 만 실제로는 선택한 별에 대해 2 개의 PNG를 만들고 선택하지 않은 별에 대해 하나씩 만들었습니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:minWidth="100dp" 
       android:orientation="horizontal"> 
    <ImageButton 
     android:id="@+id/one" 
     style="@style/RatingBar.Star"/> 
    <ImageButton 
     android:id="@+id/two" 
     style="@style/RatingBar.Star"/> 
    <ImageButton 
     android:id="@+id/three" 
     style="@style/RatingBar.Star"/> 
    <ImageButton 
     android:id="@+id/four" 
     style="@style/RatingBar.Star"/> 
    <ImageButton 
     android:id="@+id/five" 
     style="@style/RatingBar.Star"/> 
</LinearLayout> 

스타일은 다음과 같습니다 :

<style name="RatingBar.Star" parent="EmptyParent"> 
    <item name="android:layout_width">30dp</item> 
    <item name="android:layout_height">30dp</item> 
    <item name="android:layout_margin">10dp</item> 
    <item name="android:background">@drawable/star_not_selected</item> 
    <item name="android:scaleType">fitCenter</item> 
    <item name="android:onClick">onStarClicked</item> 
</style> 

그런 다음 당신은 당신의 활동에 배경을 수정 별에 클릭을 잡을 수있는 방법 public void onStarClicked(View v)을 구현 은 다음과 같은 레이아웃 XML에서 비슷한 작성 0에서 클릭 한 별까지의 이미지

+0

thx, 나는 그것을 시도 할 것이다 ^^. – Enda

0

내가 기본 RatingBar 뭐가 잘못 됐는지 몰라,하지만 난 그것을 해결 한 그 도움이된다면 setBackgroundTintList``에서`Color.TRANSPARENT`를 사용하여`setSecondaryProgressTintList`방지하고 볼이 라이브러리를 https://github.com/ome450901/SimpleRatingBar

관련 문제