在 Android 中,TableRow 内的 TextView 无法正确显示文本

发布于 2024-12-17 19:28:06 字数 1527 浏览 4 评论 0原文

我正在编写一个简单的 Android 应用程序,需要一些应该从右到左书写的文本。因此,我使用了 TableRow,如下所示:

    <?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow>
        <TextView
        android:id="@+id/ada"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_column="1"
            android:text="Open..."
            android:padding="3dip" />

    </TableRow>

    <TableRow>
        <TextView
        android:id="@+id/myview"
        android:layout_marginRight="34dip"
        android:layout_marginLeft="6dip"
        android:layout_height="100dip"
        android:layout_width="wrap_content"
        android:layout_column="1"
            android:text="Ctrl-O"
            android:gravity="right"
             />

    </TableRow>


</TableLayout>

在活动内部,我写道:

 TextView myView=(TextView)findViewById(R.id.myview);
  myView.setText("welcome 1 ");

它运行良好,并且“欢迎 1”位于右侧(根据需要)。但是,当文本长度增加时,TextView 无法正确显示文本,并且每行末尾都会超出屏幕。这是一个屏幕截图,如果我按如下方式更改上面的代码:

myView.setText("welcome 1  welcome 2  welcome 3  welcome 4  welcome 5 welcome 6  welcome 7 welcome 8 welcome 9 welcome 10 ");

在此处输入图像描述

我们将不胜感激您的帮助。

I'm writing a simple Android application that needs some text which should be written from right to left. So I used a TableRow as follows:

    <?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow>
        <TextView
        android:id="@+id/ada"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_column="1"
            android:text="Open..."
            android:padding="3dip" />

    </TableRow>

    <TableRow>
        <TextView
        android:id="@+id/myview"
        android:layout_marginRight="34dip"
        android:layout_marginLeft="6dip"
        android:layout_height="100dip"
        android:layout_width="wrap_content"
        android:layout_column="1"
            android:text="Ctrl-O"
            android:gravity="right"
             />

    </TableRow>


</TableLayout>

And inside activity, I wrote:

 TextView myView=(TextView)findViewById(R.id.myview);
  myView.setText("welcome 1 ");

It works well and the "welcome 1" is positioned on the right ( as desired). But when the length of text increases, TextView does not display the text properly and end of each line is out of screen. Here is a screenshot, if I change above code as follows:

myView.setText("welcome 1  welcome 2  welcome 3  welcome 4  welcome 5 welcome 6  welcome 7 welcome 8 welcome 9 welcome 10 ");

enter image description here

Your help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2024-12-24 19:28:06

您的 TextView 被 android:layout_marginLeft 属性推到右侧。页边距位于视图之外,您已将其设置为包裹所有内容。您可能想使用 android:layout_paddingLeft 来代替。填充放置在视图本身内部,因此不会增加它在父级中占用的空间。

Your TextView is being pushed to the right by your android:layout_marginLeft attribute. Margins are outside the view, which you've set to wrap all your content. You probably want to use android:layout_paddingLeft instead. Padding is placed inside the view itself, so does not add to the space it takes up in the parent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文