Android 在顶部和底部 ListView 上设置淡入淡出的 alpha 渐变,如 instagram 实时聊天

标签 android listview android-recyclerview

如何扩展listview(或recyclerview)设置top bottom gradient fade alpha?

enter image description here

编辑:

问题:

enter image description here

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 中时,它的顶部和底部的边界将像下图一样褪色:

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>

关于Android 在顶部和底部 ListView 上设置淡入淡出的 alpha 渐变,如 instagram 实时聊天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46721606/

相关文章:

android - 有没有办法将 TODO 标记为重要或任何其他标志?

c# - 如何在 xamarin 中使用 NotifyDataSetChange?

xaml - Windows8 ListView 和项目之间的空间

android - 在 onBindViewHolder RecyclerView 中添加滑动

android - 带有 RecyclerView 单击事件的 MotionLayout 仅在第二次单击后才起作用

java - 如何正确排序recyclerView

java - ProGuard 不会混淆蓝牙类

android - QtCreator android 不会部署

java - Toast.setGravity() 在我的 AVD Nexus 6 API 30 中不起作用

java - 当我想加载 ListView 时,Android ArrayAdapter 崩溃