简体   繁体   English

TextView对齐方式-非常常见的问题

[英]TextView Alignment - Very Common Issue

I always encounter a common problem when I have to center the text in the header which is having one button in the left. 当我必须将文本居中在标题中时,通常会遇到一个常见问题,该标题的左侧有一个按钮。

When I center the text and place it toRightOF the button it never comes in the center and when I dont take it toRight then It always overlaps with the button. 当我将文本居中并将其放置在按钮的Right位置时,它永远不会居中;当我不将其放置在Right位置时,它总是与按钮重叠。 Why is it so. 为什么会这样呢。

What is exact solution of the same? 相同的确切解决方案是什么?

<RelativeLayout
        android:id="@+id/TvHeaderRel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/zap_blue_header" >

        <com.cipl.DCC.UI.DriverMenuButton
            android:id="@+id/btnDriverMenu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/ic_menu" />

        <com.cipl.DCC.UI.TimesRomanBoldText
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_toRightOf="@+id/btnDriverMenu"
            android:ellipsize="end"
            android:gravity="center"
            android:singleLine="true"
            android:text="@string/accepted_bid_offer_details"
            android:textColor="@color/white"
            android:textSize="20sp"
            android:textStyle="bold" />
    </RelativeLayout>

Screenshot Top Header : 屏幕截图顶部标题: 在此处输入图片说明

Change to this : 更改为:

<RelativeLayout
    android:id="@+id/TvHeaderRel"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/zap_blue_header" >

    <com.cipl.DCC.UI.DriverMenuButton
        android:id="@+id/btnDriverMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/ic_menu" />

    <com.cipl.DCC.UI.TimesRomanBoldText
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/btnDriverMenu"
        android:ellipsize="end"
        android:gravity="center_vertical|center_horizontal"
        android:singleLine="true"
        android:text="@string/accepted_bid_offer_details"
        android:textColor="@color/white"
        android:textSize="20sp"
        android:textStyle="bold" />
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM