繁体   English   中英

为什么我的TextViews被移动了?

[英]Why are my TextViews being moved around?

我试图在用户点击项目后显示单个列表项。 但是,我注意到当文本太多时布局搞砸了。 有时它被推到一半,有时它完全在屏幕的右侧。 我不明白为什么会这样。 我该如何解决这个问题? 请注意我在弹出对话框中具有完全相同的布局,没有任何问题。

这是我的XML代码:

<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="1sp"
            android:layout_marginTop="2sp" >

            <TextView
                android:id="@+id/nameDetails"
                android:layout_width="fill_parent"
                android:textSize="25sp"
                android:textStyle="bold" />
        </TableRow>

        <!-- separator -->

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@android:color/darker_gray" />

        <TableRow
            android:layout_marginBottom="2sp"
            android:layout_marginTop="2sp" >

            <TextView
                android:layout_marginLeft="5sp"
                android:text="@string/distance"
                 />

            <TextView android:id="@+id/distanceDetails" />
        </TableRow>

        <TableRow
            android:layout_marginBottom="2sp"
            android:layout_marginTop="2sp" >

            <TextView
                android:layout_marginLeft="5sp"
                android:text="@string/address"
                 />

            <TextView android:id="@+id/addrDetails" />
        </TableRow>

        <TableRow
            android:layout_marginBottom="2sp"
            android:layout_marginTop="2sp" >

            <TextView
                android:layout_marginLeft="5sp"
                android:text="@string/type"
               />

            <TextView android:id="@+id/typeDetails" />
        </TableRow>

        <TableRow
            android:layout_marginBottom="2sp"
            android:layout_marginTop="2sp" >

            <TextView
                android:layout_marginLeft="5sp"
                android:text="@string/terrain" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <RatingBar
                    android:id="@+id/terrainDetails"
                    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" />
            </RelativeLayout>
        </TableRow>

        <TableRow>

            <TextView
                android:layout_marginLeft="5sp"
                android:text="@string/difficulty" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <RatingBar
                    android:id="@+id/difficultyDetails"
                    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" />
            </RelativeLayout>
        </TableRow>

        <TableRow
            android:layout_marginBottom="2sp"
            android:layout_marginTop="2sp" >

            <TextView
                android:layout_marginLeft="5sp"
                android:text="@string/description" />

            <TextView
                android:id="@+id/descDetails"
                android:gravity="top"
                android:lines="2"
                android:maxLines="2"
                android:scrollHorizontally="false" />
        </TableRow>

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@android:color/darker_gray" />
    </TableLayout>

</ScrollView>

以下是一些屏幕截图,向您展示我的意思:

应该是什么:

在此输入图像描述

不应该是什么:

推到屏幕右侧

在此输入图像描述

描述中的文字太多了。 离开屏幕

在此输入图像描述

只推了一半。

在此输入图像描述

TableLayout列的大小由其最大内容给出。

您组织布局的方式,标题名称详细信息位于第一列
您会注意到,在您不喜欢的情况下,第二列与标题的末尾整齐对齐。

要解决此问题,请将标题移出表格布局,或使用android:layout_span属性将其跨越2列

我相信这种情况正在发生,因为你将你的标题@+id/nameDetails作为表格的第一行。 当它确定表左侧的大小时,它包括此<textview>单元格的长度。

你能将那个textview移出tableview吗?

暂无
暂无

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

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