如何扩展listview(或recyclerview)设置top bottom gradient fade alpha?
编辑:
问题:
xml布局:
<RelativeLayout>
<ImageView /> // background image example: my_image.png (mach_parent)
<ListView>
</ListView>
</RelativeLayout>
最佳答案
您可以在您的 xml 中使用 requiresFadingEdge 属性。 使用以下属性在您的布局中创建一个 ListView :
android:fadingEdge="horizontal"
android:fadingEdgeLength="30dp"
android:fillViewport="false"
android:requiresFadingEdge="vertical"
因此当您的项目加载到 ListView 中时,它的顶部和底部的边界将像下图一样褪色:
所以你的代码应该是这样的:
<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>
关于Android 在顶部和底部 ListView 上设置淡入淡出的 alpha 渐变,如 instagram 实时聊天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46721606/