【问题标题】:Image with text with in bullet point带有项目符号的文本的图像
【发布时间】:2014-01-01 20:52:46
【问题描述】:

首先祝你

新年快乐。

现在进入正题。在这里我想用图标显示文本。我只能显示文本,但不能显示图标。我该怎么做?

我正在从服务器获得响应的一件重要事情。图像可以更改。整个事情都在镜头中。不是一行一行

下面是示例:

我们将不胜感激任何形式的帮助。

更新:

来自服务器的响应:

<div class=\"specsSection\">\n<p><strong>Entertainment on the Go</strong></p>\n
<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" class=\"tblSpecs\"><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/dolbyplus.jpg\" />
</td>\n<td>Sharp and Natural Sound with Digital Dolby Plus</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/wifi.jpg\" /></td>\n<td>
GPRS + WiFi (With Voice Calling)</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/lcd.jpg\" /></td>\n
<td>7\"Capacitive Touch LCD</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/dualcore.jpg\" /></td>\n
<td>Dual Core Processor</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/storage.jpg\" /></td>\n
<td>1 GB RAM, 4 GB eMMC</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/android.jpg\" /></td>\n
<td>Andorid 4.2 JellyBean</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/battery.jpg\" /></td>\n
<td>7+ hours of battery life</td>\n</tr></table></div>\n<div style=\"clear:both\">      </div>\n",

【问题讨论】:

  • 然后在同一布局中使用一个ImageView 和一个TextView

标签: android android-view


【解决方案1】:

TextView 使用android:drawableLeft="" 属性

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/image1" />

如果你想在图片和文字之间留出空间,

 android:drawablePadding="" attribute...

要动态设置图像,请使用

textView.setCompoundDrawablesWithIntrinsicBounds();

所以你正在从服务器获取图像 URL。请参阅线程 here 如何从服务器下载图像。从 Connection 获取 Stream 并使用 BitmapFactory.decodeStream() 对其进行解码。

    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
    BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
    textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);

使用 AsyncTask 下载图片并获取 Bitmap,在 UI 线程中设置为 TextView...

【讨论】:

【解决方案2】:

您可以使用android:drawableLeft="@drawable/image_at_left" 将图像精确地分配在TextView 的左侧

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/image_at_left"
    android:text="TextView" />

您可以通过编程方式设置可绘制对象..

setCompoundDrawablesWithIntrinsicBounds();

Android Doc

【讨论】:

  • can'Name can't be displayed 我收到带有 html 标签的响应我应该删除标签吗?或者你想让我在这里粘贴响应??
  • hatm 标签是什么意思??
  • 表示您需要以编程方式更改 drawableLeft ??
猜你喜欢
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-30
  • 1970-01-01
  • 1970-01-01
  • 2016-02-03
相关资源
最近更新 更多