简体   繁体   中英

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. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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