Android 如何填充listview背景

Android 如何填充listview背景,android,background,android-listview,Android,Background,Android Listview,更新1 嗯 1是什么也不做 2为listview.立根背景(可拉伸) 3是我想要的效果 listview仅填充项目的背景, 但我希望该项的背景可以填充listview的空白区域。 我能做什么 谢谢大家,, 也许我的问题还不够清楚。 我知道如何设置每个项目的背景,例如项目内部的红色。 我还知道如何使用图像集ListView背景作为空文本。 我希望使用空项背景效果来填充ListView的空viewpart。 例如正确的图像,没有项目内容,只有背景。请尝试此代码 <RelativeLayo

更新1

  • 1是什么也不做
  • 2为listview.立根背景(可拉伸)
  • 3是我想要的效果

  • listview仅填充项目的背景, 但我希望该项的背景可以填充listview的空白区域。 我能做什么

    谢谢大家,, 也许我的问题还不够清楚。 我知道如何设置每个项目的背景,例如项目内部的红色。 我还知道如何使用图像集ListView背景作为空文本。 我希望使用空项背景效果来填充ListView的空viewpart。 例如正确的图像,没有项目内容,只有背景。

    请尝试此代码

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#CCC"
     >
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />
    
    <ListView 
        android:id="@+id/list1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#6cc"
        ></ListView>
    
    
    
    试试这个:

    <ListView
    android:layout_width="match_parent "
    android:layout_height="match_parent "
    android:background="@drawable/background"
    />
    

    好的,我试着贴一张图片来解释,但是我不能

    我用一个项目(60像素)创建自定义布局,然后我得到活动的高度,再除以60像素上的活动高度,我得到应该放在屏幕上的项目数

    然后创建自定义适配器,并在getView()方法中处理文本逻辑和背景色

    现在我有了一张像你一样的照片


    关于

    这只是一个猜测,但为什么不像您这样使用setBackgroundDrawable(Drawable background),并在您的项目上将background设置为透明?当然,您的背景会被拉伸,但这样您就可以插入另一个背景图像,而不必关心物品的背景。

    对不起,您不理解我的问题。我的问题是,填补​​背景是循环的,而不是一个项目背景填充所有内容。除非你的单行背景上有填充或白色,否则你不应该看到空白。谢谢你的帮助,但是,像@mango一样,这不是我的问题,我知道如何设置项目背景。我想如果你通过将屏幕高度除以自定义布局高度来为listview创建自定义布局,你可以得到要放入arrayAdapter的项目数,我现在尝试这个解决方案哦,不……我必须这样做吗?还有其他的解决方案吗?我想这会实现你所需要的想法,如图所示