繁体   English   中英

TableLayout内部的RatingBar不一致

[英]Inconsistent RatingBar inside TableLayout

我无法在表格布局中固定评分栏。 基本上,我想要的是具有5个星标的评分栏,其准确地跨越其宽度,而与其他行的对齐方式无关。 但是要么我在显示器中获得的星星越来越多。

下面我在视觉上解释发生了什么。

试验1 :如果我在RatingBar行中不使用任何layout_span和linearlayout,RatingBar将与第二列对齐,这将导致第四列截断很多

在此处输入图片说明

试验2 :如果我将layout_span = 2或3用于评分栏,它会再次分别与第3列或第4列对齐。 现在,无论何时发生这种情况,ratingBar内的星星数量都会增加

在此处输入图片说明

试验3 :如果我将一个layout_span = 3的linearlayout放进去,并在其中放上ratingBar(当前代码),即使我的layout_width是wrap_cotent,它也不会显示全宽。

在此处输入图片说明

似乎RatingBar没有宽度来强制布局延伸到其他行跨度之外。

有人可以建议如何解决这个问题吗?

理想情况: Photoshop处理,所以发生了一些颜色失真:) 在此处输入图片说明

码:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:background="@color/bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".AddEntry" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <TableRow
            android:padding="2.5dp"
            android:background="@color/col1"
            android:gravity="center_vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="test1" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:hint="test2" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:text="test3" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:hint="test4" />

        </TableRow>

        <TableRow
            android:padding="2.5dp"
            android:background="@color/col2"
            android:gravity="center_vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="test5" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_span="3"
                android:hint="test6" />

        </TableRow>

        <TableRow
            android:padding="2.5dp"
            android:background="@color/col1"
            android:gravity="center_vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="test7" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="2"
                android:layout_marginLeft="5dp"
                android:hint="test8" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:src="@drawable/get_google" />

        </TableRow>

        <TableRow
            android:paddingLeft="2.5dp"
            android:background="@color/col2"
            android:gravity="center_vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="test9" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3" >
                <RatingBar
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:numStars="5"
                    android:stepSize="1"
                    android:rating="1" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:text="" />
            </LinearLayout>
        </TableRow>
    </TableLayout>
</ScrollView>

最好使用小等级的酒吧

 style="?android:attr/ratingBarStyleSmall"

另请参阅以下链接

如何使RatingBar显示五颗星

当与TextView在同一TableRow上时,RatingBar在Android中显示不正确

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM