【问题标题】:Android set fade alpha gradient on top and bottom listview like instagram live chatAndroid 在顶部和底部列表视图上设置淡入淡出 alpha 渐变,如 instagram 实时聊天
【发布时间】:2017-10-13 02:30:42
【问题描述】:

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

编辑:

问题:

xml 布局:

<RelativeLayout>

    <ImageView /> // background image example: my_image.png (mach_parent)

    <ListView>
    </ListView>

</RelativeLayout>

【问题讨论】:

    标签: android listview android-recyclerview


    【解决方案1】:

    您可以在 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>
    

    【讨论】:

    • 很好的答案,拯救了我的一天!
    • 这对我有用 android:fadingEdge="vertical|horizontal" android:fadingEdgeLength="30dp" android:fillViewport="false" android:requiresFadingEdge="vertical|horizontal"
    【解决方案2】:

    可以在 RecyclerView 中使用

      <androidx.recyclerview.widget.RecyclerView
          android:id="@+id/rv_list"
          android:layout_width="match_parent"
          android:orientation="horizontal/vertical"
    
          android:fadingEdge="horizontal/vertical"
          android:fadingEdgeLength="24dp"
          android:requiresFadingEdge="horizontal/vertical"
    
          tools:listitem="@layout/item_video"
          app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
          android:layout_height="wrap_content"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      • 2021-03-30
      相关资源
      最近更新 更多