2014-04-08 48 views
2

我想添加陰影到我的ListView項目的底部! 我嘗試了paddingEdageLenght,但沒有發生變化! 我加圓形邊緣,但我不能添加的項目添加陰影列表視圖的列表項底部

這是我的列表項的XML文件

<?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:fadingEdgeLength="5sp" > 

    <ImageView 
     android:id="@+id/site_image" 
     android:layout_height="50dp" 
     android:layout_width="65dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_margin="10dp"/> 

    <TextView 
     android:id="@+id/site_name" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_toRightOf="@id/site_image" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" 
     android:textSize="20sp"/> 

    <TextView 
     android:id="@+id/site_description" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_below="@id/site_name" 
     android:layout_marginTop="5dp" 
     android:layout_marginLeft="10dp" 
     android:layout_toRightOf="@id/site_image" 
     android:textSize="15sp"/> 


</RelativeLayout> 

下面的陰影,這是我的ListView XML文件

<?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" > 

    <ListView 
     android:id="@+id/near_sites" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_margin="10dp" 
     android:fadingEdgeLength="5sp" 
     android:dividerHeight="10sp" 
     android:divider="@android:color/transparent" /> 

</RelativeLayout> 

任何幫助?

+1

轉到此[http://www.anotherandroidblog.com/2011/06/29/drop-shadow-linearlayout/](http://www.anotherandroidblog.com/2011/06/29/drop-shadow -linearlayerout /) –

+0

現在,我們可以使用CardView with cardElevation和cardRaduis –

回答

6

list_view_item,在垂直LinearLayout添加虛擬查看您的RelativeLayout後,敷他們都像這樣:

<LinearLayout 
     android:orientation="vertical"> 

    <RelativeLayout> 
     ... 
     ... 
    </RelativeLayout> 

    <View 
     android:id="@+id/shadow" 
     android:layout_width="fill_parent" 
     android:layout_height="3dp" <!--or your needed height value--> 
     android:background="@drawable/shadow_drawable">  
    </View> 

</LinearLayout> 

,並在繪製文件夾添加新shadow_drawable.xml,並把這個在它

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android=」http://schemas.android.com/apk/res/android」>  
    <gradient 
     android:startColor="@color/#000000" <!--black--> 
     android:endColor="@color/#FFFFFF" <!--white--> 
     android:angle="90" <!-- angle of the gradient--> 
     > 
    </gradient> 
</shape> 
+1

在「材料設計」中,分隔線比您提議的解決方案更暗。所以,最好使用深灰色作爲形狀的起始顏色。像這樣:android:startColor =「@ android:color/darker_gray」 –

1

你必須在列表視圖中添加footerview,

如何添加footerview檢查婁代碼,

private View footerView; 
footerView = ((LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listview_footer, null, false); 
ListView.addFooterView(footerView); 

這樣,什麼都可以做,在頁腳視圖。

+1

(R.layout.listview_footer)包含什麼內容? –

+0

嗨,這是xml佈局。 –

+1

好的,這個xml包含什麼?! –

0

您可以爲陰影效果製作9貼片圖像。

創建「RES /繪製」命名爲「border.xml」新繪製資源文件,並寫入以下代碼 -

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item > 
     <shape 
      android:shape="rectangle"> 
      <gradient android:startColor="#ddd" android:endColor="#555" android:type="linear" /> 
      <corners android:radius="0dp"/> 
     </shape> 
    </item> 
    <item android:right=".5dp" android:left=".5dp" android:bottom="2dp" android:top=".5dp"> 
     <shape 
      android:shape="rectangle"> 
      <solid android:color="@android:color/white"/> 
      <corners android:radius="0dp"/> 
     </shape> 
    </item> 
</layer-list> 

只要把要申請邊境android:background="@drawable/border"

您可以更改爲android:right,android:left,android:topandroid:bottom以給出邊框的大小。您也可以在android:shape中進行更改以獲得更多效果。

希望對你有所幫助!

+0

你好,你試過這個嗎? –