2012-10-04 4 views
3

나는 XML로 설계 초보자를 해요 android:numStars가 5안드로이드 평가 바 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> 

, 그러나 이것은 내가 무엇을 얻을 :

enter image description here

은 내가 layout_widthwrap_content 너무 등급 바 별은 내 android:numStars을 따릅니다해야한다는 읽고 난로 변경할 때 내가 무엇을 얻을:

enter image description here 내가 5stars에게 평가 내 텍스트 뷰의 오른쪽 막대 (또는 내 오른쪽 화살표 이미지의 왼쪽) 감사 만들

: 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" 
    /> 

나는 안드로이드 생각 : 중력 = "center_vertical"이 문제였다.

+0

고마워요 : D 나는 당신의 XML을 시도하고 나에게 5 성급 등급 막대를 제공하지만 오른쪽 파란색 화살표 이미지가 사라집니다 ... 어떻게해야합니까? 우리는 이것을 해결하기 위해 layout_weight를 사용할 수 있습니까? –

+0

아니면 전체 XML을보고 싶습니까? : D –