谁能告诉我为什么此文本不在Android Studio中居中?

埃德奈

我正在尝试对齐文本,就像您希望看到的那样,如果您在写字板中并将对齐方式设置为居中,则每行的中间将位于屏幕的中心,而每个边距将位于屏幕的中心等距。但是,使用重力似乎无效,因为文本仍从左侧开始。有人能解释为什么吗?这是xml。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="3dp"
    android:paddingRight="3dp"
    android:paddingTop="3dp"
    android:paddingBottom="3dp"
    android:orientation="vertical"
    android:background="#111111"
    tools:context="eqlogic.annswingsandthings.AboutUs">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/chalkBoard"
        android:src="@drawable/ann_chalkboard_img"
        android:layout_weight="0.5"/>
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:id="@+id/scrollView"
        android:layout_gravity="center_horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:textColor="#999999"
            android:text="@string/AboutUsText"
            android:textSize="24sp"
            android:id="@+id/textView"
            android:layout_gravity="center_horizontal"
            android:singleLine="false" />
    </ScrollView>
</LinearLayout>
尼尔·阿尔法西(Nir Alfasi)

您没有设置重力,请使用:

android:gravity="center"

完整标签:

<TextView
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:textColor="#999999"
        android:text="@string/AboutUsText"
        android:textSize="24sp"
        android:id="@+id/textView"
        android:layout_gravity="center_horizontal"
        android:singleLine="false" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

请告诉我,为什么滚动视图在android studio中不起作用?

试图通过MPI中的多个等级绕行发送阵列,但遇到段错误。谁能告诉我为什么?

Cardview 中的居中文本 - Android Studio

谁能告诉我一种使此文本不脱离 div 背景的方法?

为什么Android Studio告诉我使用getSupportActionBar()而不是getActionBar()?

谁能告诉我如何在Python上提取并显示图像中的文本

谁能告诉我有关Android中的InternalStorage的信息?我很困惑

谁能告诉我为什么我的函数在 index.php 中有效,但在 functions.php 中无效?

谁能告诉我快速排序代码中的错误是什么

谁能告诉我这段代码在C#中到底意味着什么?

谁能告诉我代码中return与alert函数之间的区别是什么?

文本不在TableLayout中居中

谁能告诉我如何通过Android应用中的消息发送经度和纬度坐标?

谁能告诉我如何在Firebase Firestore(Android)中存储自定义对象的数组

谁能告诉我为什么尝试在菜单驱动的数组操作程序中调用Insert或Delete函数时程序崩溃?

谁能告诉我为什么 JavaScript 中的 {For} 循环返回所有值,包括数组的第一个元素?

为什么Visual Studio Code中的Python repl告诉我我的对象未定义?

谁能告诉我 laravel 中 get() 和 all() 的区别?

如何在Android Studio中垂直居中ConstraintLayout内容?

谁能告诉我python中的pika和kombu消息传递库有什么区别?

谁能告诉我Ubuntu 14.04中用于激活/使用scale / expo的关键快捷方式是什么?

为什么我的 2 个按钮不在 Div 中居中?

为什么Visual Studio告诉我我需要引用System.Private.CoreLib?

为什么Visual Studio代码告诉我cout不是std名称空间的成员?

为什么Visual Studio告诉我未定义AddJsonFile()方法?

为什么Game Maker Studio告诉我if语句不起作用?

文本不在 React JS(和 Tailwind CSS)中居中

文本不在Outlook中以“行高”垂直居中

TextBlock文本不在DataGridCell中垂直居中