Android TextView doesn't resize after changing text size

断了今生、忘了曾经 提交于 2019-12-23 17:17:33

问题


I have a ListView with some custom layout for the row (an image, then two lines of text using two TextView in a vertical LinearLayout, see code below)

My problem is that when I dynamically change the text size (in the getView method of the Adapter), the text size does change, but the size of the TextView that wraps it doesn't.

Here is a picture of what it does when I set the size to something "higher" than the default (picture is with 18). Despite the large number of threads or questions that seem similar, I haven't found a solution to that.

Here is the layout of my list row:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:padding="4dp">

    <ImageView android:id="@+id/entries_list_item_icon"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginRight="6dp"/>

    <LinearLayout android:orientation="vertical"
              android:layout_width="0dip"
              android:layout_weight="1"
              android:layout_height="fill_parent">
        <TextView android:id="@+id/entries_list_item_name"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:gravity="center_vertical"
              android:textColor="@color/entries_list_item_name"/>
        <TextView android:id="@+id/entries_list_item_summary"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:singleLine="true"
              android:ellipsize="marquee"
              android:textColor="@color/entries_list_item_summary"/>
    </LinearLayout>

</LinearLayout>

I tried switching the heights to 0dip as suggested elsewhere, it didn't change a thing.

EDIT The ListView itself is very basic:

    <ListView android:id="@+id/entries_list"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"/>

回答1:


I think you will have to change imageview height to fill_parent. Imageview is dictating the height of your layout.

<ImageView
  android:id="@+id/entries_list_item_icon"
  android:layout_width="wrap_content"
  android:layout_height="fill_parent"
  android:layout_marginRight="6dp" />


来源:https://stackoverflow.com/questions/8774431/android-textview-doesnt-resize-after-changing-text-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!