在Android中将背景图片添加到listview?

在Android中将背景图片添加到listview?,第1张

概述我正在尝试将背景图像添加到我的应用程序中的listActivity.但是,使用我使用的代码时,背景图像显示在每一行而不是整个列表中. 这是xml文件: <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:or 我正在尝试将背景图像添加到我的应用程序中的ListActivity.但是,使用我使用的代码时,背景图像显示在每一行而不是整个列表中.

这是xml文件:

<?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="8px" ><ImageVIEw    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:src="@drawable/qbg1"/><TextVIEw    androID:ID="@+ID/employeeID"    androID:layout_wIDth="50px"    androID:layout_marginRight="20px"    androID:layout_height="wrap_content"    androID:textcolor="@color/textcolor"/><TextVIEw    androID:ID="@+ID/employeename"    androID:layout_wIDth="wrap_content"    androID:layout_marginRight="10px"    androID:layout_height="wrap_content"    androID:layout_toRightOf="@ID/employeeID"    androID:textcolor="@color/textcolor"/></relativeLayout><ImageVIEw    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:src="@drawable/qbg1"/>

将背景图像添加到活动的最佳方法是什么?我更喜欢在XML文件中而不是以编程方式.

解决方法 我通过将图像背景添加到主视图,然后在该视图中添加ListVIEw来解决了这个问题.

所以这是我的main.xml文件:

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:orIEntation="vertical"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:paddingtop="4px"androID:background="@drawable/qbg"> <ListVIEw    androID:ID="@androID:ID/List"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:drawSelectorOntop="false"             androID:cachecolorHint="#00000000"/> //This is to fix disappearing background issue</relativeLayout>

这是我的ListVIEw.xml

<?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="8px" ><TextVIEwandroID:ID="@+ID/employeeID"androID:layout_wIDth="50px"androID:layout_marginRight="20px"androID:layout_height="wrap_content"androID:textcolor="@color/textcolor"/><TextVIEwandroID:ID="@+ID/employeename"androID:layout_wIDth="wrap_content"androID:layout_marginRight="10px"androID:layout_height="wrap_content"androID:layout_toRightOf="@ID/employeeID"androID:textcolor="@color/textcolor"/></relativeLayout>

希望这对其他人有益.

总结

以上是内存溢出为你收集整理的在Android中将背景图片添加到listview?全部内容,希望文章能够帮你解决在Android中将背景图片添加到listview?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1123056.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存