2017-10-13 11 views

回答

6

,你可以在你的XML使用requiresFadingEdge屬性。 做一個列表視圖佈局內與此屬性:

android:fadingEdge="horizontal" 
    android:fadingEdgeLength="30dp" 
    android:fillViewport="false" 
    android:requiresFadingEdge="vertical" 

在其頂部和底部,從而加載列表視圖中您的項目,將已經消失的邊界像下面這個圖片:

fading edge list

所以你的代碼應該是這樣的:

<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="@drawable/th" 
    tools:context="com.example.maghari_se.testfading.MainActivity"> 
<ListView 
    android:id="@+id/listview" 
    android:layout_width="match_parent" 
    android:layout_height="180dp" 
    android:layout_alignParentBottom="true" 
    android:visibility="visible" 
    android:fadingEdge="horizontal" 
    android:fadingEdgeLength="30dp" 
    android:fillViewport="false" 
    android:requiresFadingEdge="vertical"> 

</ListView> 

+0

偉大的回答,拯救了我的一天! – MohammadReza

-2

requiresFadingEdge給我一個很難的時候,當回收者視圖只有1個元素(我從底部填充)它褪色的第一個項目從下面,然後,只要回收商成爲阿爾法切換到頂部,試圖解決它,並沒有成功。

然後我發現this lib,它的工作就像一個魅力。

希望這可以幫助你!

+0

儘管這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/ review/low-quality-posts/18460819) –

相關問題