【问题标题】:When Text in Table is long, other table shape is distorted当表格中的文本很长时,其他表格形状会变形
【发布时间】:2021-06-25 10:02:10
【问题描述】:

我想要的是当文本很长时,表格形状不应该扭曲。如我添加的图像所示,第一个文本很长,其他单元格和文本已损坏。我想解决这个问题。

<TableLayout
        android:id="@+id/table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginVertical="30dp"
        android:layout_marginHorizontal="10dp"
        android:background="#f1f1f1"
        >

        <TableRow>
            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:orientation="horizontal" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:maxLines="1"
                android:text="fospfdmglfdmglğpkdsağgorjgdfglkdfdsfsdfsdfg"
                android:layout_weight="1"
                android:gravity="center"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Email"
                android:textStyle="bold"
                android:layout_weight="1"
                android:gravity="center"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tel"
                android:textStyle="bold"
                android:layout_weight="1"
                android:gravity="center"/>
            </LinearLayout>
            </HorizontalScrollView>

        </TableRow>

        <TableRow>

【问题讨论】:

  • 你希望它表现如何?
  • 如果文本很长,文本可能会缩小或向下滑动而不破坏单元格。只要不打乱单元格的顺序,整张图片都会因为1个单元格而失真

标签: java android android-studio android-layout text-size


【解决方案1】:

请检查此代码,我更改了 layout_width 并且工作正常。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <TableLayout
        android:id="@+id/table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginVertical="30dp"
        android:layout_marginHorizontal="10dp"
        android:background="#f1f1f1">


    <TableRow>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal" >
                <TextView
                    android:layout_weight=".5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:text="fospfdmglfssssssssssssssssdfglkdfdsfsdfsdfg"
                    />

                <TextView
                    android:layout_weight="1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Email"

                    android:textStyle="bold"
                    android:gravity="center"/>


                <TextView
                    android:layout_weight="1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Tel"
                    android:textStyle="bold"
                    android:gravity="center"/>
            </LinearLayout>

    </TableRow>



    </TableLayout>
</LinearLayout>

【讨论】:

  • 我不明白要检查什么,它不能正常工作,我还是寻求帮助来解决这个问题?
  • 我的意思是请试试这个代码,我已经解决了重量问题。
  • 最后谢谢你,我怎样才能使电子邮件和电线部分与 1ststun 一样大小?
  • 抱歉,没找到你。
  • 你发的e-mail和tel名字的部分很小,我希望第一部分大一点,大小一样,写的时候不要溢出。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-05
  • 2022-01-23
  • 1970-01-01
相关资源
最近更新 更多