2

I am developing layout to show last 4 digits of credit card and card type image. If none of the cards are selected it will show some other text which is longer than 4 digit card number. Once the card is selected it shows properly in TextView, but when longer text is set, it's not showing properly. TextView is not expanding its width for longer text.

Image with 4 digit card number

enter image description here

Image with long text

enter image description here

Here is the whole xml code:

<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<RelativeLayout
    android:id="@+id/headerLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/margin_20"
    android:paddingRight="@dimen/margin_20"
    android:background="@color/ConfirmAndPayHeaderColor">
    <TextView
        android:id="@+id/CancelButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/CancelButton"
        android:background="@null"
        android:textColor="@drawable/TransparentButtonBgText"
        android:textAllCaps="false"
        android:textSize="@dimen/text_Size_17"
        android:paddingTop="@dimen/margin_15"
        android:paddingBottom="@dimen/margin_15"
        fontPath="@string/FontRobotoRegular"
        android:layout_centerVertical="true" />
    <TextView
        android:id="@+id/TitleText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/pay"
        android:layout_centerInParent="true"
        android:textColor="@color/black"
        android:textSize="@dimen/text_Size_17"
        android:paddingTop="@dimen/margin_15"
        android:paddingBottom="@dimen/margin_15"
        fontPath="@string/FontRobotoRegular" />
</RelativeLayout>
<View
    android:layout_width="match_parent"
    android:layout_height="@dimen/height_1"
    android:background="@color/DividerLightGrey" />
<RelativeLayout
    android:id="@+id/LocationLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/margin_20"
    android:paddingRight="@dimen/margin_20">
    <TextView
        android:id="@+id/LocationLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/PickupLocation"
        android:textAllCaps="false"
        android:textSize="@dimen/text_Size_13"
        android:paddingTop="@dimen/margin_15"
        android:paddingBottom="@dimen/margin_15"
        android:layout_centerVertical="true"
        android:textColor="@color/lightGray"
        fontPath="@string/FontRobotoRegular" />
    <TextView
        android:id="@+id/ChangeButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Change"
        android:textSize="@dimen/text_Size_13"
        android:background="@null"
        android:textColor="@drawable/TransparentButtonBgText"
        android:layout_alignParentRight="true"
        android:paddingTop="@dimen/margin_15"
        android:paddingBottom="@dimen/margin_15"
        android:layout_centerVertical="true"
        fontPath="@string/FontRobotoRegular" />
    <TextView
        android:id="@+id/LocationTitleText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Terrel Plaza"
        android:textSize="@dimen/text_Size_13"
        android:layout_centerHorizontal="true"
        android:textColor="@color/black"
        android:gravity="center"
        android:paddingTop="@dimen/margin_15"
        android:paddingLeft="@dimen/margin_3"
        android:paddingRight="@dimen/margin_3"
        android:layout_toRightOf="@id/pickupLocationLabel"
        fontPath="@string/FontRobotoBold"
        android:layout_toLeftOf="@id/ChangeButton" />
    <TextView
        android:id="@+id/LocationDetailText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="San Antonio, TX"
        android:textSize="@dimen/text_Size_13"
        android:gravity="center"
        android:layout_centerHorizontal="true"
        android:textColor="@color/lightGray"
        android:layout_below="@id/LocationTitleText"
        android:paddingBottom="@dimen/margin_15"
        android:paddingLeft="@dimen/margin_3"
        android:paddingRight="@dimen/margin_3"
        android:layout_toRightOf="@id/pickupLocationLabel"
        android:layout_toLeftOf="@id/ChangeButton"
        fontPath="@string/FontRobotoRegular" />
</RelativeLayout>
<View
    android:layout_width="match_parent"
    android:layout_height="@dimen/height_1"
    android:background="@color/DividerLightGrey"
    android:layout_marginLeft="@dimen/margin_20" />
<RelativeLayout
    android:id="@+id/paymentLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="@dimen/margin_20"
    android:paddingRight="@dimen/margin_20"
    android:paddingBottom="@dimen/margin_15"
    android:paddingTop="@dimen/margin_15">
    <TextView
        android:id="@+id/paymentLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Payment"
        android:textSize="@dimen/text_Size_13"
        android:textColor="@color/lightGray"
        fontPath="@string/FontRobotoRegular"
        android:paddingTop="@dimen/margin_3"
        android:layout_gravity="center_vertical"/>
    <LinearLayout
        android:id="@+id/paymentDetLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="horizontal"
        android:gravity="center_vertical">
        <ImageView
            android:id="@+id/cardImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:src="@drawable/card_visa"
            android:layout_marginRight="@dimen/margin_8" />
        <TextView
            android:id="@+id/cardNoText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/AddCard"
            android:textColor="@color/black"
            android:textSize="@dimen/text_Size_13"
            android:layout_marginRight="@dimen/margin_10"
            fontPath="@string/FontRobotoRegular" />
        <ImageView
            android:id="@+id/paymentDropDown"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/down_arrow" />
    </LinearLayout>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
    android:id="@+id/paymentListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/margin_10"
    android:paddingRight="@dimen/margin_10"
    android:visibility="gone"
    android:layout_below="@+id/paymentMethodLayout" />
<Button
    android:id="@+id/addPaymentTypeButton"
    android:layout_below="@id/paymentListView"
    android:layout_width="wrap_content"
    android:layout_marginBottom="@dimen/margin_10"
    android:layout_height="wrap_content"
    android:background="@null"
    android:textColor="@drawable/TransparentButtonBgText"
    android:textAllCaps="false"
    android:textSize="@dimen/text_Size_22"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center"
    android:gravity="center"
    android:visibility="gone"
    fontPath="@string/FontUnited"
    android:text="@string/AddPaymentType" />
<View
    android:id="@+id/paymentDivider"
    android:layout_width="match_parent"
    android:layout_height="@dimen/height_1"
    android:background="@color/DividerLightGrey"
    android:layout_marginLeft="@dimen/margin_20" />
<RelativeLayout
    android:id="@+id/pickupTimeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/margin_20"
    android:paddingRight="@dimen/margin_20">
    <TextView
        android:id="@+id/pickUpTimeLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/PickupTime"
        android:textSize="@dimen/text_Size_13"
        android:paddingTop="@dimen/margin_15"
        android:paddingBottom="@dimen/margin_15"
        android:layout_centerVertical="true"
        android:textColor="@color/lightGray"
        fontPath="@string/FontRobotoRegular" />
    <TextView
        android:id="@+id/pickUpTimeText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="4:35 PM"
        android:textSize="@dimen/text_Size_12"
        android:textColor="@color/black"
        android:layout_alignParentRight="true"
        android:paddingTop="@dimen/margin_15"
        android:paddingBottom="@dimen/margin_15"
        android:layout_centerVertical="true"
        fontPath="@string/FontRobotoBold" />
</RelativeLayout>
<View
    android:layout_width="match_parent"
    android:layout_height="@dimen/height_1"
    android:background="@color/DividerLightGrey"
    android:layout_marginLeft="@dimen/margin_20" />
<RelativeLayout
    android:id="@+id/TotalLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/margin_20"
    android:paddingRight="@dimen/margin_20">
    <TextView
        android:id="@+id/TotalLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/OrderTotal"
        android:textSize="@dimen/text_Size_13"
        android:paddingTop="@dimen/margin_15"
        android:paddingBottom="@dimen/margin_15"
        android:layout_centerVertical="true"
        android:textColor="@color/lightGray"
        fontPath="@string/FontRobotoRegular" />
    <TextView
        android:id="@+id/TotalText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="$5.77"
        android:textSize="@dimen/text_Size_13"
        android:textColor="@color/black"
        android:layout_alignParentRight="true"
        android:paddingTop="@dimen/margin_15"
        android:paddingBottom="@dimen/margin_15"
        android:layout_centerVertical="true"
        fontPath="@string/FontRobotoRegular" />
</RelativeLayout>
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/PlaceOrder"
    android:id="@+id/placeOrderButton"
    android:textAllCaps="false"
    android:textSize="@dimen/text_Size_25"
    android:textStyle="bold"
    android:textColor="@color/white"
    android:background="@drawable/OrangeRectButton"
    android:layout_marginLeft="@dimen/margin_20"
    android:layout_marginRight="@dimen/margin_20"
    android:layout_marginTop="@dimen/margin_5"
    android:layout_marginBottom="@dimen/margin_15"
    fontPath="@string/FontUnited" />
</LinearLayout>

Below is the xml code only for the row where I am facing issue:

<RelativeLayout
    android:id="@+id/paymentLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="@dimen/margin_20"
    android:paddingRight="@dimen/margin_20"
    android:paddingBottom="@dimen/margin_15"
    android:paddingTop="@dimen/margin_15">
    <TextView
        android:id="@+id/paymentLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Payment"
        android:textSize="@dimen/text_Size_13"
        android:textColor="@color/lightGray"
        fontPath="@string/FontRobotoRegular"
        android:paddingTop="@dimen/margin_3"
        android:layout_gravity="center_vertical"/>
    <LinearLayout
        android:id="@+id/paymentDetLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="horizontal"
        android:gravity="center_vertical">
        <ImageView
            android:id="@+id/cardImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:src="@drawable/card_visa"
            android:layout_marginRight="@dimen/margin_8" />
        <TextView
            android:id="@+id/cardNoText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/AddCard"
            android:textColor="@color/black"
            android:textSize="@dimen/text_Size_13"
            android:layout_marginRight="@dimen/margin_10"
            fontPath="@string/FontRobotoRegular" />
        <ImageView
            android:id="@+id/paymentDropDown"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/down_arrow" />
    </LinearLayout>
</RelativeLayout>
Aju
  • 4,597
  • 7
  • 35
  • 58

2 Answers2

3

Did you try to call these two functions on the TextView after updating the text?

textView.invalidate();
textView.requestLayout();

Explanation: https://stackoverflow.com/a/42430695/1062074

Updated

Following will work, requestLayout on parent layout will work.

parentLayout.requestLayout(); 
Aju
  • 4,597
  • 7
  • 35
  • 58
chrjs
  • 2,375
  • 1
  • 25
  • 41
0
 please try this hope it will work.

   <RelativeLayout
   android:id="@+id/paymentLayout"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:gravity="center_vertical"
   android:paddingLeft="@dimen/margin_20"
   android:paddingRight="@dimen/margin_20"
   android:paddingBottom="@dimen/margin_15"
  android:paddingTop="@dimen/margin_15">
  <TextView
    android:id="@+id/paymentLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Payment"
    android:textSize="@dimen/text_Size_13"
    android:textColor="@color/lightGray"
    fontPath="@string/FontRobotoRegular"
    android:paddingTop="@dimen/margin_3"
    android:layout_gravity="center_vertical"/>
<LinearLayout
    android:id="@+id/paymentDetLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:orientation="horizontal"
    android:weightSum="3"
    android:gravity="center_vertical">
    <ImageView
        android:id="@+id/cardImage"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:src="@drawable/card_visa"
        android:layout_marginRight="@dimen/margin_8" />
    <TextView
        android:id="@+id/cardNoText"
         android:layout_width="0dp"
        android:layout_weight="2"
        android:layout_height="wrap_content"
        android:text="@string/AddCard"
        android:textColor="@color/black"
        android:textSize="@dimen/text_Size_13"
        android:layout_marginRight="@dimen/margin_10"
        fontPath="@string/FontRobotoRegular" />
    <ImageView
        android:id="@+id/paymentDropDown"
        android:layout_width="0dp"
        android:layout_weight="2"
        android:layout_height="wrap_content"
        android:background="@drawable/down_arrow" />
</LinearLayout>

umesh shakya
  • 237
  • 2
  • 12