【问题标题】:TextView inside a TableRow does not display text, properly, in AndroidTableRow 中的 TextView 在 Android 中无法正确显示文本
【发布时间】:2012-01-06 13:34:00
【问题描述】:

我正在编写一个简单的 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 ");

您的帮助将不胜感激。

【问题讨论】:

    标签: android alignment tablerow


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-07-10
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 2023-03-29
      • 2022-01-01
      • 1970-01-01
      相关资源
      最近更新 更多