Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to center two textViews with different font-size

<LinearLayout
    android:id="@+id/layout_information"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="0.17"
    android:gravity="center"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/text_view_destination"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="\@ Home in"
        android:textColor="@color/solid_white"
        android:textSize="19sp"
        android:textStyle="bold" 
        android:layout_gravity="bottom"
        />

    <TextView
        android:id="@+id/text_view_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:textColor="@color/solid_white"
        android:textSize="25sp"
        android:textStyle="normal" 
        android:layout_gravity="bottom"
        />
</LinearLayout> 

I want to center the two textViews vertically,

but I want them to be aligned to one line at their bottom.

Now they are alined to the same bottom,

but they are at the bottom of their parent layout.

How can I do this?

I have thought to wrap their current layout parent ("parent1") with another layout ("parent2")

and make "parent1" be in the center of "parent2".

Is there another way without adding elements?

like image 405
Elad Benda Avatar asked Dec 12 '25 05:12

Elad Benda


1 Answers

If your problem is that both views are aligned at the bottom of their parent you can use this. Both views are still aligned to the same bottom and centered on the screen.

Your layout looks like a part of a bigger XML (weight=0.17), that is why I have used fill_parent on layout_width.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_information"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.17"
android:gravity="center"
android:orientation="horizontal" >

    <TextView
    android:id="@+id/text_view_destination"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="\@ Home in"
    android:textColor="@color/solid_white"
    android:textSize="19sp"
    android:textStyle="bold" />

    <TextView
    android:id="@+id/text_view_time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:layout_marginLeft="30dp"
    android:text="\@ Home in"
    android:textColor="@color/solid_white"
    android:textSize="25sp"
    android:textStyle="normal"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@id/text_view_destination"
    android:layout_alignBaseline="@id/text_view_destination" />

</RelativeLayout>
like image 200
AlexBcn Avatar answered Dec 13 '25 17:12

AlexBcn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!