3

私は XML を使ったデザインの初心者です :D これは私の評価バーと友人の XML です :

 <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:numStars5ですが、これは私が得るものです:

ここに画像の説明を入力

評価バーの星が私の後に続くようにするlayout_width必要があることを読みました。これを に変更すると、次のようになります。wrap_contentandroid:numStarswrap_content

ここに画像の説明を入力

テキストビューの右側 (または右矢印画像の左側) に 5 つ星の評価バーを作成したい ありがとう :D

4

2 に答える 2

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:gravity="center_vertical"が問題だったと思います。

于 2012-10-04T09:47:16.300 に答える
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>

そして、このコードは私のレイアウトを「完璧」にします

于 2012-10-05T03:44:43.467 に答える