Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can´t center textview´s text vertically

[Solved] I had to add android:fillViewport="true" to the ScrollView, that fixed the problem with the text not centering vertically.

I know this has been answered many times before, but I´m still not able to center a textview´s text vertically.

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/relativelayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/icon"
            android:layout_width="@dimen/icon_width"
            android:layout_height="@dimen/icon_height"
            android:src="@drawable/picture" />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/icon"
            android:gravity="center_vertical"
            android:layout_alignBottom="@+id/icon"
            android:layout_alignTop="@+id/icon"
            android:text="@string/title_text"
            android:textSize="@dimen/textsize"
            android:textStyle="bold"
            android:textColor="@color/color"
            android:shadowColor="@color/shadow"
            android:shadowRadius="5"/>

        </RelativeLayout>
</ScrollView>

Normally this should work with

android:gravity="center_vertical"

but it has no effect on the textview...

Weird thing is that I have a second app with the exact same code and it´s working there without any problems.

/edit

To clarify my question: This is what I have right now:
http://i.imgur.com/WwHCegq.png

This is what I want:
http://i.imgur.com/9T8CyT6.png

like image 706
f4bzen Avatar asked Sep 10 '13 16:09

f4bzen


1 Answers

To achieve the result you want, it will be enough to remove

android:gravity="center_vertical"
android:layout_alignBottom="@+id/icon"
android:layout_alignTop="@+id/icon"

and add

android:layout_centerVertical="true"

instead.

like image 172
lomza Avatar answered Sep 29 '22 18:09

lomza