简体   繁体   English

如何在透明ListView下放置背景?

[英]How do I put a background under a transparent ListView?

right now what I have is just a listview with a custom gradient as the background color. 现在,我所拥有的只是一个带有自定义渐变作为背景色的列表视图。 When I have 2 items in my list, the rest of the background beneath it is just all black. 当我的列表中有2个项目时,它下面的其余背景全都是黑色。 I can't set a background image anywhere that would make a background show up. 我无法在任何会显示背景的地方设置背景图像。 My desired outcome is to have a background image in the back of the entire view where a transparent listview would overlay it. 我希望得到的结果是在整个视图的后面有一个背景图像,其中透明的列表视图将其覆盖。 How could this be done? 怎么办呢? Let me know if you guys need more info/code from my project. 让我知道你们是否需要我项目中的更多信息/代码。

Thanks! 谢谢!

This is my listview in main.xml 这是我在main.xml中的列表视图

<ListView
    android:id="@+id/store_list2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/store_div2"
    android:divider="#000000"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_selector"/>

This is the list_selector.xml 这是list_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
 android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@drawable/gradient_bg" />

<item android:state_pressed="true"
    android:drawable="@drawable/gradient_bg_hover" />

<item android:state_selected="true"
 android:state_pressed="false"
    android:drawable="@drawable/gradient_bg_hover" />
</selector>

this is my list_row.xml 这是我的list_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:padding="10dp" >

<!--  Application Icon -->
<LinearLayout 
    android:id="@+id/gmg_thumbnail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="3dp"
    android:layout_alignParentLeft="true"
    android:background="@drawable/image_bg"
    android:layout_marginRight="5dp">

    <ImageView
        android:id="@+id/gmg_list_image"
        android:layout_width="50dp"
        android:layout_height="50dp" />

</LinearLayout>

<!-- Title-->
<TextView
    android:id="@+id/gmg_title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="10dp"
    android:layout_toRightOf="@id/gmg_thumbnail"
    android:textColor="#040404"
    android:typeface="sans"
    android:textSize="15sp" />

 <!-- Rightend Arrow -->
 <ImageView 
    android:contentDescription="@string/right_arrow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/scaled_arrow"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"/>

</RelativeLayout>

Set your desired background on the Parent Layout containing ListView. 在包含ListView的父布局上设置所需的背景。

android:background="@drawable/ic_launcher" 

Like this (Assuming RelativeLayout is yout parent layout) 这样(假设RelativeLayout是您的父级布局)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_launcher" >

   <ListView
    android:id="@+id/store_list2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/store_div2"
    android:divider="#000000"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_selector"/>

</RelativeLayout>

将此属性android:cacheColorHint="#00000000"到ListView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM