在 Android 中,TableRow 内的 TextView 无法正确显示文本
我正在编写一个简单的 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 ");
Your help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 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 useandroid:layout_paddingLeft
instead. Padding is placed inside the view itself, so does not add to the space it takes up in the parent.