TableRow中的TextView在Android中不能正确显示文本
我正在编写一个简单的Android应用程序,它需要一些从右到左书写的文本。因此,我使用了一个TableRow,如下所示:TableRow中的TextView在Android中不能正确显示文本,android,alignment,tablerow,Android,Alignment,Tablerow,我正在编写一个简单的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=
<?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>
myView.setText("welcome 1 welcome 2 welcome 3 welcome 4 welcome 5 welcome 6 welcome 7 welcome 8 welcome 9 welcome 10 ");
它运行良好,“欢迎1”位于右侧(根据需要)。但是,当文本长度增加时,TextView无法正确显示文本,并且每行的结尾都在屏幕外。下面是一个屏幕截图,如果我将上述代码更改如下:
<?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>
myView.setText("welcome 1 welcome 2 welcome 3 welcome 4 welcome 5 welcome 6 welcome 7 welcome 8 welcome 9 welcome 10 ");
非常感谢您的帮助。您的
android:layout\u marginLeft
属性将您的文本视图推到右侧。页边距位于视图之外,您已将其设置为包装所有内容。您可能想改用android:layout\u paddingLeft。填充放置在视图本身内部,因此不会增加它在父视图中所占的空间。您的文本视图正被您的android:layout\u marginLeft
属性推到右侧。页边距位于视图之外,您已将其设置为包装所有内容。您可能想改用android:layout\u paddingLeft。填充放置在视图本身内部,因此不会增加它在父视图中占用的空间