Android的等级吧xml和numStars等级、Android、numStars、xml

2023-09-07 13:02:52 作者:碎了一地的真心

我是一个初学者在XML设计:D 这是我的评价的酒吧和朋友们的XML:

I'm a beginner in designing with XML :D This is the XML of my rating bar and friends :

 <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>

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

The android:numStars is 5, but this is what i get :

我读了 layout_width 必须 WRAP_CONTENT 这样的评价吧星星会按照我的 Android的:numStars ,这是我所得到的,当我将其更改为 WRAP_CONTENT

I read that the layout_width must be wrap_content so the rating bar stars will follow my android:numStars and this is what i get when i change it to wrap_content :

我要创建5stars我的TextView的正确评价杆(或我的右箭头图像左) 谢谢:D

推荐答案

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

Okay, i have an idea to use a relative layout and i also use a little drag-drop :

<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>

这code使我的布局完美

And this code make my layout "perfect"