【问题标题】:Is it possible to programmatically resize a TextView inside a widget?是否可以在小部件内以编程方式调整 TextView 的大小?
【发布时间】:2012-08-02 15:11:11
【问题描述】:

作为学习练习,我正在开发一个非常简单的原生 Android 小部件。

小部件有一个包含单个 ImageView 和单个 TextView 的 RelativeLayout。 TextView 填充了从 Web 服务中提取的名称,而 ImageView 填充了相同的 url。

TextView 的位置如下:android:layout_toRightOf="@+id/image"

我的基本问题是尝试调整 TextView 的大小以适合其中的内容。我只能弄清楚如何在 TextView 布局 xml 中提供显式或继承的宽度。

我真正想要的是这样的:

似乎无法在小部件正在使用的 RemoteView 中获取 TextView 的句柄,因此我似乎无法即时调整它的大小。

有没有推荐的方式来实现上述布局?

【问题讨论】:

  • android:layout_width = "wrap_content" ?

标签: android android-layout android-widget


【解决方案1】:

文本视图

android:layout_width="wrap_content"
android:layout_alignParentRight="true"

图像视图

android:layout_toLeftOf="@+id/lTextView"

【讨论】:

    【解决方案2】:

    就像 0gravity 建议的那样,android:layout_width = "wrap_content"。然后使用填充来调整文本周围的空间,直到看起来符合需要。

    【讨论】:

      猜你喜欢
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多