2017-01-22 11 views
0

RatingBarのコードは次のとおりです。評価バーにすべての星が表示されていません

<RatingBar 
    android:layout_height="wrap_content" 
    android:layout_width="0dp" 
    android:rating="4" 
    android:id="@+id/product_rating" 
    android:isIndicator="false" 
    android:numStars="5" 
    android:stepSize="0.0" 
    android:max="5" 
    app:layout_constraintRight_toLeftOf="@+id/guideline4" 
    tools:layout_constraintTop_creator="1" 
    tools:layout_constraintRight_creator="1" 
    android:layout_marginTop="8dp" 
    tools:layout_constraintLeft_creator="1" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginStart="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginEnd="8dp" 
    android:layout_marginRight="8dp"/> 

しかし、私はマックススターとステップサイズ値と最大値を設定するには、次の属性を使用しているにもかかわらず、私は5目に見える星を持っている必要があります。私はネクサス10風景を見ている場合、私はこの取得

Enter image description here

::私は間違って何をやっている enter image description here

をしかし....は、私はこのような結果を得ますか?

追加:私はそれを言うことは非常に困難だ親のレイアウトを見ることなく、再び同じ問題

<LinearLayout 
    android:layout_width="0dp" 
    android:orientation="vertical" 
    android:layout_height="wrap_content" 
    android:layout_weight="30"> 
    <RatingBar 
     android:id="@+id/rating_bar_product_stats" 
     android:layout_width="wrap_content" 
     android:layout_gravity="center" 
     android:max="5" 
     android:numStars="5" 
     android:layout_height="wrap_content"/> 
    <TextView 
     android:id="@+id/rating_string_product_stats" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 

答えて

2

設定android:layout_width="wrap_content"なくandroid:layout_width="0dp" ため、使用android:layout_width="0dp"あれば、それは、デバイスの幅に基づいて、5つ以上の星が表示される場合がありandroid:layout_weight="1"を設定します。上記のコードを1として

アップデート1 私は私だけ

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<LinearLayout 
android:layout_width="0dp" 
android:orientation="vertical" 
android:layout_height="wrap_content" 
android:layout_weight="30"> 
<RatingBar 
    android:id="@+id/rating_bar_product_stats" 
    android:layout_width="wrap_content" 
    android:layout_gravity="center" 
    android:max="5" 
    android:numStars="5" 
    android:layout_height="wrap_content"/> 
<TextView 
    android:text="4.4" 
    android:id="@+id/rating_string_product_stats" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /> 
</LinearLayout> 
</LinearLayout> 

enter image description here

+0

did not work forme – erluxman

+0

@LaxmanBhattarai完全なレイアウトxmlファイルを投稿してください。 –

+0

編集 – erluxman

2

をこのレイアウトを使用しています。あなたがorientation="vertical"を設定していないLinearLayoutのリンクを見かけます(水平レイアウトが必要な場合を除く)。また、android:layout_width="0dp"の設定はlayout_weight属性なしでは奇妙です。

私がお勧めします:

<RatingBar 
    android:id="@+id/rating" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:numStars="5" 
    android:stepSize="0.1" 
    android:isIndicator="true" /> 

し、あなたのコード内を:

findViewById(R.id.rating).setRating(int) 

あなたは私のレイアウト(親コンテナ)の多くを与えた場合、私はおそらくより多くのを助けることができます。

+0

親は1つしかなく、制約レイアウトです – erluxman

1

評価バーの下に出力を参照してくださいすべての5つ星を取得し、これを使用する場合には、応じてUIの幅を取ります1つの星のサイズにするため、評価バーに割り当てられたスペースが少ない場合は、より小さい星が表示され、評価バーに割り当てられたスペースが必要以上に大きい場合は、星示されているのはもっとです。 これを解決するには2つの方法がありますが、5つの星にしたがって評価バーの幅を修正するか、5つのチェックボックスまたはイメージビューを使用して、快適で快適な画像を表示することができます。

関連する問題