2012-10-04 43 views
3

我是一个初学者与XML设计:d 这是我的评级酒吧和朋友的XML:安卓评级酒吧XML和numStars

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="2" > 

    <TextView 
     android:id="@+id/txtTitle" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 
     android:layout_weight="1" 
     android:gravity="center_vertical" 
     android:textColor="#336699" 
     android:textSize="18dp" 
     android:textStyle="bold" /> 

    <RatingBar 
     android:id="@+id/rtbHighScore" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 
     android:numStars="5" 
     android:max="100" 
     android:rating="0.0" 
     android:stepSize="0.0" 
     style="?android:attr/ratingBarStyleSmall"   
     android:layout_weight="1" /> 

    <ImageView 
     android:id="@+id/imgRow" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="right" 
     android:layout_marginBottom="5dp" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="5dp" 
     android:gravity="center_vertical" 
     android:src="@drawable/rightarrow" /> 
</LinearLayout> 

android:numStars是5,但是这是我所得到的:

enter image description here

我读了layout_width必须wrap_content因此额定酒吧星星会跟着我android:numStars,这是我所得到的,当我将其更改为wrap_content

enter image description here

我想创建5stars在我的TextView权等级栏(或我的右箭头图像的左) 感谢:d

+0

任何帮助,请真的卡住了?这里:D –

回答

2

好吧,我有一个主意,用一个相对布局,我也用一个小拖放:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="2" > 

    <TextView 
     android:id="@+id/txtTitle" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 
     android:layout_marginLeft="5dp" 
     android:gravity="center_vertical" 
     android:textColor="#336699" 
     android:textSize="18dp" 
     android:textStyle="bold" 
     android:layout_weight="1" 
     /> 

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

     <RatingBar 
      android:id="@+id/rtbHighScore" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="15dp" 
      android:layout_marginTop="15dp" 
      android:layout_marginRight="45dp" 
      android:numStars="5" 
      android:max="100" 
      android:rating="0.0" 
      android:stepSize="0.0" 
      style="?android:attr/ratingBarStyleSmall" 
      /> 

     <ImageView 
      android:id="@+id/imgRow" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="96dp" 
      android:src="@drawable/rightarrow" /> 

    </RelativeLayout> 
</LinearLayout> 

而这种代码让我的布局“完美”的

+0

谢谢!我遇到了完全相同的问题,并解决了这个问题 –

+0

如何使用自定义评分来给星星之间的空间? – Shadow

4

使用正确此版式文件5星。

<TextView 
    android:id="@+id/txtTitle" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginBottom="5dp" 
    android:layout_marginTop="5dp" 
    android:layout_weight="1" 
    android:gravity="center_vertical" 
    android:textColor="#336699" 
    android:textSize="18dp" 
    android:textStyle="bold" /> 

<RatingBar 
    android:id="@+id/rtbHighScore" 
    style="?android:attr/ratingBarStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:layout_marginRight="45dp" 
    android:max="5" 
    android:numStars="5" 
    android:rating="0.0" 
    android:stepSize="0.0" /> 

<ImageView 
    android:id="@+id/imgRow" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="right" 
    android:layout_marginBottom="5dp" 
    android:layout_marginRight="15dp" 
    android:layout_marginTop="5dp" 
    android:gravity="center_vertical" 
    /> 

我认为Android:重力= “center_vertical” 是问题。

+0

感谢:D 我试过你的xml,它给了我一个5星级的评级栏,但右边的蓝色箭头图像消失了......我该怎么办?我们可以使用layout_weight来解决这个问题吗? –

+0

或者你也许想看到我的整个XML? :D –