使用阵列适配器上的图像的Andr​​oid ListView项显示文本 [英] Android listview item display text over image using array adapter

查看:118
本文介绍了使用阵列适配器上的图像的Andr​​oid ListView项显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经超载的ListView的getView方法来填充列表项的自定义样式。

I have overloaded the getView method of listview to populate custom style of list item.

这就是目前它看起来像:!!

This is what currently it looks like:!!

红色是只显示列表视图项的背景

在这里,我用3控制:ImageView的图像,文字2视图(一个顶部,一个底线)

Here I have used 3 controls: Imageview for image, 2 text views (one top, one bottom).

问题这里列表视图项目的高度越来越增加。我想在不高于或低于影像产生两个textviews。要someextent我知道这个问题的根本原因,但不知道如何解决它。

Problem here is the height of listview item is getting increased. I want two textviews over the image not above or below. To someextent I know the root cause of this problem but don't know how to fix it.

下面是ListView项的布局:

Here is the layout of listview item:

<?xml version="1.0" encoding="utf-8"?>

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

  <ImageView android:id="@+id/imgIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="5dp" 
    android:scaleType="fitCenter"/>

   <TextView android:id="@+id/txtTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="top"
    android:textStyle="bold"
    android:textSize="20sp"
    android:textColor="#FFFFFF"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="2dp"
    android:layout_alignLeft="@+id/imgIcon"
    android:layout_alignTop="@+id/imgIcon"
    android:layout_alignBottom="@+id/imgIcon"/>

   <TextView android:id="@+id/txtTime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="bottom"
    android:textStyle="bold"
    android:textSize="18sp"
    android:textColor="#FFFFFF"
    android:layout_marginLeft="10dp"
    android:layout_marginBottom="5dp"
    android:layout_alignLeft="@+id/imgIcon"
    android:layout_alignTop="@+id/imgIcon"
    android:layout_alignBottom="@+id/imgIcon"/>

问题是我使用PNG图像ImageView的和他们的大小是在某些方面比得到提高。在情况下,我很难code ListView项布局的高度,然后,特别是在我的手机屏幕尺寸,事情开始出现不错,但在某些不同的屏幕大小事情变得更糟完全(这是有道理的太)。

The problem is i'm using png image for Imageview and their size is getting increased in some aspect ratio. In case I hard code the height of listview item layout then, specifically on my phone screen size, things start appearing good but on some different screen size things get totally worse (which makes sense too).

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" 
android:layout_width="fill_parent"
android:layout_height="70dp"
android:padding="5dp"   >

将是巨大的,如果有人可以了解如何做到这一点解释。主要问题是在图像上显示文字(和图像不一样的)。谢谢你。

Would be great if someone can explain about how to do it. Main problem is to display text over an image (and image is not same). Thanks.

更新:我的主要问题是,我没有图像的位矢量,而不是一个PNG文件并试图扩大的形象。 (设置规模类型为中心的配合可能是一个选项,但它会在后台资源工作的?的这里是输出,如果我设置的图像作为列表视图项的背景下,并在它两个文本。

Update: My major problem is I don't have the bit vector of image instead a PNG and it tries to scale up the image. (setting scale type to center-fit could be an option but would it work on background resourcE?. Here is the output if I set image as a background for listview item and two texts over it.

推荐答案

好吧,在你CustomArrayAdaptor调用getView()的时候,而不是ImageView的位图设置为你的形象(你正在做什么,我相信),而不是在您的视图调用View.setBackgroundResource(R.drawable.yourimage.png)你infalted后。在XML中的等价物是如下:

Ok, when calling getView() in your CustomArrayAdaptor, rather than set the ImageView bitmap to the image you have (what you are currently doing, I believe), instead call View.setBackgroundResource(R.drawable.yourimage.png) on your view after you have infalted it. The equivalent in xml is below:

的android:背景=@绘制/ yourimage

android:background="@drawable/yourimage".

如果您需要更多的信息,让我知道。

If you need more information, let me know.

这篇关于使用阵列适配器上的图像的Andr​​oid ListView项显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆