0

I have the following issue. My list view elements consist of two buttons positioned in a row:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">

<Button
    android:id="@+id/time_field"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/task_field"
    android:layout_alignTop="@+id/task_field"
    android:layout_centerVertical="true"
    android:layout_marginEnd="5dp"
    android:layout_marginRight="5dp"
    android:clickable="false"
    android:enabled="true"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:longClickable="false"
    android:paddingLeft="2dp"
    android:paddingRight="2dp"
    android:textColor="@color/black_col" />

<Button
    android:id="@+id/task_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toEndOf="@+id/time_field"
    android:clickable="false"
    android:enabled="true"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:gravity="center|start"
    android:longClickable="false"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"/>

So what happens im the app is that the second (right) button is got filled with the text (by user) which can be of 2, 3 and more lines, whereas text in the left button is always in single line. So, what I want is to make the first (left) button be always of the same height as the right one, which varies depending on the number of text lines. Also the text line in the left button should be in the center.

Now I only can make buttons of equal height (using layout_alignBottom and layout_alignTop) but the text in the left button is always on top.

As far as I understand this happens due to rendering of the list view item is completed after the height is set, but I don't know how to overcome this. I've tried to set left button height equal to the right one programmatically in my list view adapter but it helps only when I tap on a list view item and not when the list is filled or scrolled!

Please help me to overcome this! Thanks!

userVadim
  • 80
  • 2
  • 7
  • Also try setting `layout_height` = `match_parent` instead of `wrap_content`, then it will respect the top and bottom bounds you've set and ensure the `time_field` button takes up the same space as the `task_field` button. – Elliptica Jul 24 '19 at 16:37

1 Answers1

1

As such there is no native method to resize text view.But you can find useful implementations on Auto Scale TextView Text to Fit within Bounds or you can resize the text to fit within bounds. Look at this for more help How to adjust text font size to fit textview

Community
  • 1
  • 1
Shubham
  • 1,288
  • 2
  • 11
  • 32