圆圈中的Android文本不在中心

圆圈中的Android文本不在中心,android,Android,为什么会这样?如何修复它? 我在API 23和res 2560x1440上运行应用程序 在具有相同API的平板电脑上,一切正常 <TextView android:id="@+id/time_view" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginTop="10dp" android:layout_marginLeft="10dp"

为什么会这样?如何修复它? 我在API 23和res 2560x1440上运行应用程序 在具有相同API的平板电脑上,一切正常

<TextView
    android:id="@+id/time_view"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:background="@drawable/red_circle"
    android:lineSpacingMultiplier="0.7"
    android:textColor="@color/white"
    android:textSize="@dimen/text_size_circle_list_view"
    android:lines="2"
    android:textStyle="bold"

    android:layout_centerVertical="true"
    android:orientation="vertical"
    android:layout_alignParentTop="true"
    android:textAlignment="center"
    android:text="00\n00"
    android:gravity="center" />

尝试添加 android:padding=“2dp”

尝试添加
android:padding=“2dp”

我的意见不使用circletextview。易于使用,适用于所有设备。请参阅链接

请参阅下面的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/num_txt"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginTop="0dp"
            android:background="@drawable/bg_red"
            android:gravity="center"
            android:text="My name is NON"
            android:textColor="#FFFFFF"
            android:textSize="10dp" />

    </RelativeLayout>

</RelativeLayout>

保存在drawable bg_red.xml中


编辑代码


我的意见不使用circletextview。易于使用,适用于所有设备。请参阅链接

请参阅下面的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/num_txt"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginTop="0dp"
            android:background="@drawable/bg_red"
            android:gravity="center"
            android:text="My name is NON"
            android:textColor="#FFFFFF"
            android:textSize="10dp" />

    </RelativeLayout>

</RelativeLayout>

保存在drawable bg_red.xml中


编辑代码



正是android:lineSpacingMultiplier=“0.7”属性规范将其从中心剔除。通常,请尝试删除对视图外观并非绝对重要的所有属性。

正是android:lineSpacingMultiplier=“0.7”属性规范将其从中心剔除。一般来说,尝试删除对视图外观并非绝对重要的所有属性。

您是否随机填充了所有想到的属性?许多属性(如方向)不适用于文本视图
android:lineSpacingMultiplier=“0.7”
-为什么需要它?试着不用它看看是否有用。@MohammedAtif差不多)我尝试了很多东西,但都给了我错误的结果(@milosmns thx太多了,这就解决了我的问题。我需要它来减少行距,然后我可以使文本更大,它适合循环工具,然后我将它作为答案发布:)但是如果你不需要,就不要添加随机属性。你是否随机填充了你脑海中出现的所有属性?许多属性(如方向)不适用于文本视图
android:lineSpacingMultiplier=“0.7”
-为什么需要它?试着不用它看看是否有用。@MohammedAtif差不多)我尝试了很多东西,但都给了我错误的结果(@milosmns thx太多了,这就解决了我的问题。我需要它来减少行距,然后我可以使文本更大,它适合循环工具,然后我将它作为答案发布:)但是,如果不需要,不要添加随机属性。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-感谢您审阅我的答案@MiladFaridnia。你的想法是对的。但我只添加了堆栈溢出链接。我认为堆栈溢出链接永远不会改变。欢迎您,但我建议您在此处添加答案的基本部分;)虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-感谢您审阅我的答案@MiladFaridnia。你的想法是对的。但我只添加了堆栈溢出链接。我认为堆栈溢出链接永远不会改变。欢迎您,但我建议您在此处添加答案的基本部分;)
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >
     <TextView
         android:id="@+id/num_txt"
         android:layout_width="185dp"
         android:layout_height="185dp"

         android:layout_alignParentTop="true"
         android:layout_marginTop="163dp"
         android:background="@drawable/bg_red"
         android:gravity="center"
         android:text="My name is NON"
         android:textColor="#FFFFFF"
         android:layout_marginLeft="10dp"
         android:textSize="10dp" />

     <TextView
         android:id="@+id/TextView02"
         android:layout_width="90dp"
         android:layout_height="90dp"
         android:layout_alignParentRight="true"
         android:layout_alignTop="@+id/TextView01"
         android:layout_marginRight="90dp"
         android:layout_marginTop="122dp"
         android:background="@drawable/bg_red"
         android:gravity="center"
         android:text="My name is NON"
         android:textColor="#FFFFFF"
         android:textSize="10dp" />

     <TextView
         android:id="@+id/TextView01"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_alignTop="@+id/num_txt"
         android:layout_toRightOf="@+id/num_txt"
         android:background="@drawable/bg_red"
         android:gravity="center"
         android:text="My name is NON"
         android:textColor="#FFFFFF"
         android:textSize="10dp" />

</RelativeLayout>