Android TextView does not expand to match parent

岁酱吖の 提交于 2019-12-06 07:55:35
venimania

Your android:padding="8dp" is making this.

If you want to have padding just on top and bottom, use

android:paddingBottom="8dp"
android:paddingTop="8dp"

If I understand correctly you want to remove the tips and promos field entirely when there are no tips and promos, and display the red notes section to match parent.

In which case make the LinearLayout llTipsPromos gone. This will fill the parent with the red notes section

Try below code -

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llNotesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tracking_bg_note">

<LinearLayout
    android:id="@+id/llNotes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/llTipsPromos"
    android:layout_alignParentLeft="true"
    android:orientation="vertical"
    android:padding="8dp" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/tracking_notes"
        android:textColor="@color/tracking_font_address"
        android:textSize="13sp"/>

    <TextView
        android:id="@+id/tvNotes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="2"
        android:ellipsize="end"
        android:textColor="@color/tracking_font_note"
        android:textSize="15sp"
        android:background="@color/red"/>
</LinearLayout>

 <View
    android:id="@+id/vVerticalSeparator"
    android:layout_toRightOf="@+id/llNotes"
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:layout_marginBottom="8dp"
    android:layout_marginTop="8dp"
    android:background="@color/tracking_separator"/>

Tips and Promos
<LinearLayout
    android:id="@+id/llTipsPromos"
    android:layout_width="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical"
    android:gravity="center_vertical">

    <LinearLayout
        android:id="@+id/llTips"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:visibility="visible"
        android:gravity="center_vertical"
        android:padding="8dp">

        <TextView
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:text="@string/tracking_tips"
            android:textColor="@color/tracking_font_address"
            android:textSize="13sp"/>

        <TextView
            android:id="@+id/tvTips"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/tracking_font_note"
            android:textSize="15sp"
            android:singleLine="true"
            android:ellipsize="end"/>
    </LinearLayout>

    <View
        android:id="@+id/vHorizontalSeparator"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/tracking_separator"/>

    <LinearLayout
        android:id="@+id/llPromos"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:padding="8dp">

        <TextView
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:text="@string/tracking_promo"
            android:textColor="@color/tracking_font_address"
            android:textSize="13sp"/>

        <TextView
            android:id="@+id/tvPromos"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/tracking_font_note"
            android:textSize="15sp"
            android:singleLine="true"
            android:ellipsize="end"/>
    </LinearLayout>
</LinearLayout> 

when you want to show note view on full screen then hide your llTipsPromos LinearLayout.It will sure work for you.

Finally I found a way to cope with the issue. This is the change. Hope helps you in case you have similar issue.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llNotesContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/tracking_bg_note"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/llNotes"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:padding="8dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/tracking_notes"
            android:textColor="@color/tracking_font_address"
            android:textSize="13sp"/>

        <TextView
            android:id="@+id/tvNotes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/tracking_font_note"
            android:textSize="15sp"
            android:background="@color/red"/>
    </LinearLayout>

    <View
        android:id="@+id/vVerticalSeparator"
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:background="@color/tracking_separator"/>

    <!-- Tips and Promos -->
    <LinearLayout
        android:id="@+id/llTipsPromos"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center_vertical">

        <LinearLayout
            android:id="@+id/llTips"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:padding="8dp">

            <TextView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:text="@string/tracking_tips"
                android:textColor="@color/tracking_font_address"
                android:textSize="13sp"/>

            <TextView
                android:id="@+id/tvTips"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/tracking_font_note"
                android:textSize="15sp"/>
        </LinearLayout>

        <View
            android:id="@+id/vHorizontalSeparator"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/tracking_separator"/>

        <LinearLayout
            android:id="@+id/llPromos"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:padding="8dp">

            <TextView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:text="@string/tracking_promo"
                android:textColor="@color/tracking_font_address"
                android:textSize="13sp"/>

            <TextView
                android:id="@+id/tvPromos"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/tracking_font_note"
                android:textSize="15sp"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!