Android TextView strange text alignment

时间:2016-10-20 18:52:45

标签: android android-layout textview text-alignment

In many different questions the answer to align the text inside a TextView was either: android:layout_width="match_parent" or to set the gravity or textAlignment however none of these options seemed to work on my emulator. I don't have the preview since it's code generated text. Using my current layout I get this in my emulator: enter image description here Why does the black text behave in such a strange way? I want to left align it. This is my current xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:font="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context="com.domain.citytour.activity.ImpressumActivity">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/locationTitle"
                android:textAlignment="center"
                android:padding="@dimen/activity_horizontal_margin"
                android:background="@color/primary"
                android:textColor="@color/cardview_light_background"
                android:textSize="20sp"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:textAlignment="viewStart"
                android:id="@+id/locationContent"
                android:padding="@dimen/activity_horizontal_margin"
                android:textColor="@color/primary_text"
                android:textSize="14sp"/>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

I'm sorry to bother this comunity again with this question.

1 个答案:

答案 0 :(得分:0)

<TextView
        android:text="Left Text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start|left"/>

Here's a similar question: Android TextView Align text to Right and Left