java - 在android中右对齐文本?

标签 java android layout tableview

为了让 <TableLayout> 中的文本右对齐,我需要做什么特别的事情吗? ?

下面的简单示例似乎将文本右对齐到屏幕中央,就好像 layout_span 一样。没有影响。

<TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        >
    <TableRow>
        <TextView
                android:text="Some text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_span="2"
                />
    </TableRow>
    <TableRow>
        <Button
                android:text="Button 1"
                android:layout_weight="50"/>
        <Button
                android:text="Button 2"
                android:layout_weight="50"/>
    </TableRow>
</TableLayout>

最佳答案

已修复。

从 TextView 中删除部分:

android:layout_gravity="right"
android:layout_span="2"

TextView 中的更新部分:

android:gravity="right"
android:layout_weight="1.0"


 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="fill_parent"
      android:layout_width="fill_parent" >

      <TableRow>
           <TextView
                 android:text="Some text"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:gravity="right"
                 android:layout_weight="1.0" />
      </TableRow>
      <TableRow>
            <Button
                 android:text="Button 1"
                 android:layout_weight="50"/>
            <Button
                 android:text="Button 2"
                 android:layout_weight="50"/>
       </TableRow>
 </TableLayout>

关于java - 在android中右对齐文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5711046/

相关文章:

java - Netflix Zuul 服务器-/路由端点不可用

android - 如何准确使用Ratingbar?

android - 同一个数据库的多个 DatabaseHelper

Android 布局文件夹 : layout, layout-port, layout-land

qt - 在pyqt中设置布局边距

java - 数据库查询中断

java - 将 unix 时间转换为工作日

java - 我需要帮助。我正在编写一个有 GUI 的程序

android - 如何在 Android 中以编程方式获取 PATH 环境变量的值?

html - 使用 CSS 布局 float 和清除的页面元素