java - Android - 页面标题与背景左中对齐

标签 java android layout

无论文本大小如何,页面标题都位于背景的左侧中心,这是一个问题。

无论文本大小如何,文本都应位于背景中心。

我为 TextView 使用了以下layout.xml:

    <TableLayout
           android:id="@+id/widget3d8"
           android:layout_width="306dip"
           android:layout_height="26dip"
           android:gravity="fill_horizontal"
           android:paddingRight="8px"
           android:layout_x="5px"
           android:layout_y="10px"
           android:layout_weight="1" 
           android:background="#104082">
            <TextView android:id="@+id/committeename"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_x="0px"
                      android:layout_y="100px"
                      android:paddingLeft="10px"
                      android:text=" "
                      android:textSize="12sp"
                      android:textStyle="bold"
                      android:textColor="#ffffff"/>
              </TableLayout>

请帮助我如何使文本在背景上左居中,无论文本大小如何。提前致谢。

最佳答案

我将使 TextView 具有与其父级相同的高度,并设置重力以使内容垂直居中。

<TextView android:id="@+id/committeename"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:layout_x="0px"
    android:layout_y="100px"
    android:paddingLeft="10px"
    android:text=" "
    android:textSize="12sp"
    android:textStyle="bold"
    android:textColor="#ffffff"/>

关于java - Android - 页面标题与背景左中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8352160/

相关文章:

java - 使用 MIDP RMS 存储数据并在 PC 中检索

java - 无法将按钮文本设置为 "<<<"

android - Android 选项卡中的典型搜索、结果和详细信息工作流

android - 在谷歌眼镜上录制音频

android - SurfaceView Inflate Button 在纵向底部居中

java - 从 TabbedPane 中的不同选项卡访问数据 - Java

java - JAX-RS 中的 Provider 是什么意思?

java - 数据类型字符串的大型数组

android - CountDownTimer 与 AlarmManager

android - 海拔不适用于 LinearLayout