繁体   English   中英

评分栏未在单行中显示所有星级

[英]rating bar not show all star in single row

我的评级栏未完全排成一行,请参见图片http://imgur.com/vRGrXU1最后一颗星不会完全显示我将如何解决此问题,请帮助我如何将其固定到评级栏中,将所有5星级完全显示给我

           <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical"
 android:padding="10sp" >

 <EditText
    android:id="@+id/Email"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Email"
    android:singleLine="true" >

    <requestFocus />
</EditText>


   <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

  android:textColor="#ffffff"

    android:text="Give rating"
    android:textAppearance="?android:attr/textAppearanceLarge" />

  <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:numStars="5"
        android:stepSize="1"
        android:rating="0" />





 <EditText
    android:id="@+id/Comments"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:layout_marginTop="10dp"
         android:hint="Comments"
   android:minLines="3" >
 </EditText>

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/Submitbtn"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
             android:layout_marginLeft="10dp"
        android:text="Submit" />

    <Button
        android:id="@+id/btn_cancel"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/Submitbtn"
        android:text="Cancel" />
   </RelativeLayout>

     </LinearLayout>

尝试这个-

<RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1"
        android:rating="0" />

这减小了RatingBar的宽度。

您也可以使用Style -

看到这个链接。

RatingBar需要一个静态宽度,而您没有它,因为它不会自动调整其星形大小,因此请找到一个空格而不是

<RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1"
        android:rating="0" />

你需要

<RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="150dp" <!-- or whatever static size that fits-->
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1"
        android:rating="0" />

- 编辑 -
如果您想使其变小但不如@nurisezgin答案那么大,您可以为RatingBar设置样式,但还需要静态宽度,如果您在对话框中使用该布局,则可以采用另一种解决方案,即可以设置该对话框的最小宽度,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical"
 android:minWidth="300dp"
 android:padding="10dp" > // also use dp for padding instead of sp

如果您设置了会发生什么

机器人:layout_width = “FILL_PARENT”

或将静态宽度设置为

机器人:layout_width = “300dp”

您可以更改评分栏属性吗? 试试这个attrs;

<RatingBar
    android:id="@+id/ratingBar"
    style="?android:attr/ratingBarStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:isIndicator="true"
    android:numStars="5"
    android:stepSize="1" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM