【问题标题】:Android TextView doesn't resize after changing text size更改文本大小后,Android TextView 不会调整大小
【发布时间】:2012-02-05 03:53:26
【问题描述】:

我有一个 ListView 和一些自定义的行布局(一个图像,然后是两行文本,在垂直 LinearLayout 中使用两个 TextView,请参见下面的代码)

我的问题是,当我动态更改文本大小时(在AdaptergetView 方法中),文本大小确实会发生变化,但包裹它的TextView 的大小不会。

这是当我将大小设置为“高于”默认值时它所做的图片(图片为 18)。尽管有大量看起来相似的主题或问题,但我还没有找到解决方案。

这是我的列表行的布局:

<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>

我尝试按照其他地方的建议将高度切换为 0dip,但没有任何改变。

编辑 ListView 本身非常基本:

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

【问题讨论】:

  • 您是否尝试过将height 属性更改为wrap_content
  • 唯一不在 wrap_content 的是垂直 LinearLayout,所有其他的已经是。是的,我也尝试过更改这个(我只是再次尝试),没有更改 - LinearLayout 环绕两个 TextView,但每个 TextView 的大小已经不正确......
  • 对不起,我的意思是width 属性!但现在我发现这可能不是你的问题。
  • 不,宽度“对于屏幕来说太宽”我很好,我只想根据需要修改 TextViews(和整个列表项)的高度。

标签: java android textview font-size


【解决方案1】:

我认为您必须将 imageview 高度更改为 fill_parent。 Imageview 决定了布局的高度。

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

【讨论】:

  • 有效!哇,非常感谢。 ImageView 高度如何决定整个布局?是因为它是 LinearLayout 上的第一个吗?
  • 25 分钟得到解决方案。我喜欢 StackOverflow ;)
  • 我自己也不确定,但看到你的图片,布局高度似乎被限制为图片高度
猜你喜欢
  • 1970-01-01
  • 2014-10-30
  • 1970-01-01
  • 1970-01-01
  • 2016-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多