[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:
This is what I want:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With