![](/img/trans.png)
[英]How do i put a horizontal listview of boxdecoration under another boxdecoration?
[英]How do I put a background under a transparent ListView?
現在,我所擁有的只是一個帶有自定義漸變作為背景色的列表視圖。 當我的列表中有2個項目時,它下面的其余背景全都是黑色。 我無法在任何會顯示背景的地方設置背景圖像。 我希望得到的結果是在整個視圖的后面有一個背景圖像,其中透明的列表視圖將其覆蓋。 怎么辦呢? 讓我知道你們是否需要我項目中的更多信息/代碼。
謝謝!
這是我在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"/>
這是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>
這是我的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>
在包含ListView的父布局上設置所需的背景。
android:background="@drawable/ic_launcher"
這樣(假設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.