HGamble
HGamble

Reputation: 435

Multi-line text view has two different behaviours

I want the text in my text-view to wrap when it is too long. When I first open the activity the extra text is not visible. When I turn the phone the text fits. When I turn it back again the text is wrapped, but the tops and bottoms of the text are cut off. How can I fix this? Thanks.

Also, why do I get different behaviour when I open the activity and after turning it back to vertical? pic 1 pic 2 pic 3

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal"
android:minHeight="@dimen/list_item_height"
android:background="@color/color_accent_two">

<ImageView
    android:id="@+id/image"
    android:layout_width="@dimen/list_item_height"
    android:layout_height="@dimen/list_item_height"
    />

<LinearLayout
    android:id="@+id/text_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:background="@color/color_accent_two">

    <TextView
        android:id="@+id/tajikTextView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom"
        android:text="New Text"
        android:textColor="@color/color_accent_one"
        android:textAppearance="?android:textAppearanceMedium"
        android:textStyle="bold"/>
    <TextView
        android:id="@+id/englishTextView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:text="New Text"
        android:textColor="@color/color_accent_three"
        android:textAppearance="?android:textAppearanceMedium"
        />
    <TextView
        android:id="@+id/tajikLatinTextView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:text="New Text"
        android:textColor="@color/color_accent_three"
        android:textAppearance="?android:textAppearanceMedium"
        />

</LinearLayout>

Upvotes: 1

Views: 370

Answers (1)

Andy Developer
Andy Developer

Reputation: 3101

Try this one: Remove the weight and set TextView height wrap_content.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:background="@color/color_accent_two"
    android:minHeight="@dimen/list_item_height"
    android:orientation="horizontal">

<ImageView
    android:id="@+id/image"
    android:layout_width="@dimen/list_item_height"
    android:layout_height="@dimen/list_item_height" />

<LinearLayout
    android:id="@+id/text_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_accent_two"
    android:orientation="vertical"
    android:paddingLeft="16dp">

    <TextView
        android:id="@+id/tajikTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:textAppearance="?android:textAppearanceMedium"
        android:textColor="@color/color_accent_one"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/englishTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:textAppearance="?android:textAppearanceMedium"
        android:textColor="@color/color_accent_three" />

    <TextView
        android:id="@+id/tajikLatinTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:textAppearance="?android:textAppearanceMedium"
        android:textColor="@color/color_accent_three" />
</LinearLayout>

Upvotes: 1

Related Questions