无法更改评分的宽度和星号数
问题描述:
我试图设置仅有5星的RatingBar
,但它会展开以填充屏幕的宽度。无法更改评分的宽度和星号数
我也发现了类似的问题:
- How to make RatingBar to show five stars
- Android RatingBar - a complete mess
- android rating bar xml and numStars
然而,大多数的解决方案是将宽度设置为wrap_content
的时间,但宽度我一直是wrap_content
。
这是我的布局。如果向右滚动至底部,您会看到两个RatingBar
S:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/add_spot_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="1" >
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Distance:" />
<TextView android:id="@+id/distancePopup" />
</TableRow>
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Address:" />
<TextView android:id="@+id/addrPopup" />
</TableRow>
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Type:" />
<TextView android:id="@+id/typePopup" />
</TableRow>
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Terrain:" />
<RatingBar
android:id="@+id/terrainPopup"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:max="5"
android:numStars="5"
android:stepSize="1" />
</TableRow>
<TableRow>
<TextView android:text="Difficulty:" />
<RatingBar
android:id="@+id/difficultyPopup"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:max="5"
android:numStars="5"
android:stepSize="0.1" />
</TableRow>
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Description:" />
<TextView
android:id="@+id/descPopup"
android:gravity="top"
android:lines="2"
android:maxLines="2"
android:scrollHorizontally="false" />
</TableRow>
</TableLayout>
</ScrollView>
这是什么样子:
答
在表布局您使用的是像
android:shrinkColumns="1"
android:stretchColumns="1"
这里缩小和拉伸相同的列号。
我删除了
android:stretchColumns="1"
而且它为我工作。
最终布局
<TableLayout
android:id="@+id/add_spot_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1" >
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Distance:" />
<TextView android:id="@+id/distancePopup" />
</TableRow>
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Address:" />
<TextView android:id="@+id/addrPopup" />
</TableRow>
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Type:" />
<TextView android:id="@+id/typePopup" />
</TableRow>
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Terrain:" />
<RatingBar
android:id="@+id/terrainPopup"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:max="5"
android:numStars="5"
android:stepSize="1" />
</TableRow>
<TableRow>
<TextView android:text="Difficulty:" />
<RatingBar
android:id="@+id/difficultyPopup"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:max="5"
android:numStars="5"
android:stepSize="0.1" />
</TableRow>
<TableRow
android:layout_marginBottom="2sp"
android:layout_marginTop="2sp" >
<TextView android:text="Description:" />
<TextView
android:id="@+id/descPopup"
android:gravity="top"
android:lines="2"
android:maxLines="2"
android:scrollHorizontally="false" />
</TableRow>
</TableLayout>
答
对于未来的Google,
由阿米特答案帮助我的问题:该评级窗口小部件被显示方式太多的明星。
这是因为该小部件已被设置为android:layout_width="wrap_content"
以考虑数字标记。
答
我认为这可以通过在RELATIVELAYOUT中嵌套RATINGBAR来解决。我认为这个问题是因为TableLayout的本质是在任何情况下填充父项,RATINGBAR取父项的宽度。所以我解决了这个嵌套在RELATIVELAYOUT里的RATINGBAR,并为WRAP_CONTENT(RATINGBAR和RELATIVE LAYOUT)设置了LAYOUT_WIDTH和LAYOUT_HEIGT。只有在这种情况下,我才能在TABLELAYOUT中使用RATINGBAR。
希望帮助;)
答
使用相对布局作为评价巴父母或评级酒吧 和WRAP_CONTENT将解决您的问题
这解决了这个问题对我来说 - 这应该他高了 – user43043 2018-02-27 00:16:25