与标题,图片和文字列表视图? [英] List view with title, image and text?
问题描述
我需要做一个列表视图与左图像,标题浮动的形象的权利,并根据该说明。 我已签出的文档列表视图,但我似乎无法找到一个这样的例子。 我在XML定义(按照机器人为例TABS1)标签视图列表视图作为第一个选项卡的内容。 不过,我想通过推荐内容添加内容到code中的列表视图。
I need to make a list view with an image on left, a title floated right of that image and a description under that. I have checked out the list view in the docs but i cannot seem to find an example for this. I have a tab view as defined in XML (as per android example tabs1) with a list view as the first tab content. However i want to add the content via a RSS newsfeed to the listview in code.
我想用用HTML注入字符串的WebView,但如何将我从绘制文件夹中插入图片。 (这些图像是只是一个新闻图标本地存储的,而不是从互联网的图像)
I was thinking of using a webview using an html injection string but how would i insert images from the drawable folder. (these images are just a "news icon" stored locally, not an image from the internet)
很抱歉,如果这是一个有点nooby问题,但任何帮助AP preciated:)
Sorry if it is a bit of a nooby question, but any help appreciated :)
推荐答案
我想,你所描述的结构是指到ListView项的内容。可以通过定义一个布局的单个项实现这一点。在code以下已经在类似情况下为我工作:
I suppose that the structure you are describing refers to the content of the ListView items. You can achieve this by defining a layout for the individual item. The code below has worked for me in a similar situation:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:padding="6dip" android:layout_height="?android:attr/listPreferredItemHeight">
<ImageView
android:id="@+id/result_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:src="@drawable/image1"/>
<TextView
android:id="@+id/result_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/result_icon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="Title" />
<TextView
android:id="@+id/result_second_line"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="@id/result_icon"
android:layout_below="@id/result_name"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Second line" />
</RelativeLayout>
然后,您需要扩展BaseAdapter与您的ListActivity使用。您将需要膨胀的布局,并与来自RSS提要的数据填充它。
You then need to extend a BaseAdapter to use with your ListActivity. You will need to inflate the layout and populate it with data from the RSS feed.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Result result = this.results.get(position);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout view = (RelativeLayout)
inflater.inflate(R.layout.result_item, null, false);
ImageView image = (ImageView) view.findViewById(R.id.result_icon);
image.setImageResource(result.imageResource);
TextView name = (TextView) view.findViewById(R.id.result_name);
name.setText(result.location);
TextView secondLine = (TextView) view.findViewById(R.id.result_second_line);
secondLine.setText(result.shortDescription);
return view;
}
这篇关于与标题,图片和文字列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!