android 评级栏 xml 和 numStars

2023-12-08

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

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

enter image description here

我读到layout_width必须是wrap_content所以评级栏星星会跟随我的android:numStars这就是我将其更改为时得到的结果wrap_content :

enter image description here

我想在文本视图的右侧(或右箭头图像的左侧)创建 5 星评级栏感谢:D


使用此布局文件可获得适当的 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" 是问题所在。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android 评级栏 xml 和 numStars 的相关文章

随机推荐