2016-09-22 7 views
1

に星の高さと幅を大きくする私はratingbarを実装していると私は、添付された画像以下のようなratingbarを設定したいが、問題はratingbarでその私がratingbar幅のmatch_parentを使用し、その後以上の5つ星ショーです。私の評価バーを添付画像として実装する方法や、実装方法を教えてもらえますか? はここにここに私の主な活動である私のactivity_mainアンドロイドどのratingbar

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="gymtrainer.com.ratinbarexample.MainActivity"> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     android:text="Rate 5 star for RatingBar" 
     /> 


    <RatingBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     style="@style/foodRatingBar" 
     android:id="@+id/ratingbar_default" 
     android:maxWidth="250dp" 
     android:numStars="5" 
     android:stepSize="0.1" 
     /> 


    <TextView 
     android:id="@+id/textView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="show state up checkbox" 
     android:textColor="#CC00CC" 
     android:textSize="20dp" 
     /> 


</LinearLayout> 

です。 SimpleRatingBar

public class MainActivity extends Activity { 

    RatingBar ratingbar1; 
    Button button; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     addListenerOnButtonClick(); 

    } 

    public void addListenerOnButtonClick(){ 

     final TextView text = (TextView) findViewById(R.id.textView); 

     final RatingBar ratingBar_default = (RatingBar)findViewById(R.id.ratingbar_default); 

     final Button button = (Button)findViewById(R.id.button1); 
     button.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       ratingBar_default.setRating(5); 
       text.setText("Rating: "+String.valueOf(ratingBar_default.getRating())); 
      } 
     }); 

     ratingBar_default.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){ 
      @Override 
      public void onRatingChanged(RatingBar ratingBar, float rating, 
             boolean fromUser) { 
       // TODO Auto-generated method stub 
       text.setText("Rating: "+String.valueOf(rating)); 
      }}); 
    } 
} 

は、ここでは、Androidのデフォルトに異なるRatingBarを使用して喜んでいる場合は、私はの生みの親だ自分のスタイル

<style name="foodRatingBar" parent="@android:style/Widget.RatingBar"> 
    <item name="android:progressDrawable">@drawable/star_rating_bar_full</item> 
    <item name="android:minHeight">100dip</item> 
    <item name="android:maxHeight">100dip</item> 
</style> 

enter image description here

+0

Androidはアイコンの縮尺を調整しません。ですから、単にあなたのカスタムアイコンを使い、 'minHeight'と' maxHeight'を設定するだけです。 – Ironman

+1

私はカスタムライブラリを使用してコンパイル 'com.iarcuschin:simpleratingbar:0.0.10' – amorenew

+0

@ amorenew助けてくれてありがとう。ライブラリなしでこれを行うことはできないのですか? –

答えて

1

です。

それは特徴:

  • が完全android:layout_width作業:それはwrap_contentmatch_parentまたはabritary DPに設定することができます。
  • 任意の星数です。
  • 任意のステップサイズ。
  • 星の大きさを正確に制御することも、最大サイズを設定することもできます。
  • 通常の状態(星の枠線、塗りつぶし、背景、評価バー)でカスタマイズ可能な色です。
  • 押された状態(星の境界線、塗りつぶし、背景、評価バー)でカスタマイズ可能な色。
  • 星間のサイズをカスタマイズすることができます。
  • カスタマイズ可能な星の幅。
  • カスタマイズ可能な星の角の半径。
  • OnRatingBarChangeListenerを設定できるようにする
  • スターフィルは、左から右または右から左に開始するように設定できます(RTL言語サポート)。
  • AnimationBuilderは、アニメーションでプログラマチックにレーティングを設定するビューに統合されています。

Here is a preview of it

jcenterまたはMaven Centralのいずれかにあります。だからあなたのbuild.gradleファイルにちょうどあなたの依存関係に追加します。あなたの例では

compile 'com.iarcuschin:simpleratingbar:0.1.+'

を、あなたはとしてそれを使用することはできません。

<com.iarcuschin.simpleratingbar.SimpleRatingBar 
     android:id="@+id/ratingbar_default" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     app:srb_numberOfStars="5" 
     app:srb_stepSize="0.1" 
     app:srb_starSize="100dp" 
     app:srb_borderColor="@color/your_light_green_color" 
     app:srb_fillColor="@color/your_light_green_color" 
     /> 

必要な余分なxmlファイルを:)

私は願っていますそれは便利です。

関連する問題