背景
列表展示数据时,有些数据因为失效了,需要灰化展示。但是因为每一行数据里面包含多个view(如包含用户姓名、性别等等信息),不方便对每个view进行灰化设置,所以需要一个遮罩层将整行遮盖来达到灰化效果。大致效果如下:
解决方案
列表的item布局采用RelativeLayout或者ConstraintLayout,在layout中增加一个空的view(遮罩层),刚好能盖住其他view,默认设置为不可见。在adapter里根据数据的有效性设置是否打开这层遮罩层。
带遮罩的item布局文件样例如下:
其中maskLayer为遮罩层view,如下几点需要重点注意:
android:layout_height="30dp" 这个高度要设置为固定的值,必须刚好和view原本高度相同,不能设置为wrap_content或match_parent。所以此方案不适用于item的高度不固定的情况。
android:background="#80F9F9F9" 设置遮罩层的颜色,前两位是透明度(00到FF,值越小越透明。)
android:clickable="true"和android:focusable="true" 是为了屏蔽点击事件,让点击失效。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginLeft="8dp" android:layout_marginTop="8dp" android:textColor="@android:color/black" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="TextView" /> <View android:id="@+id/maskLayer" android:layout_width="match_parent" android:layout_height="30dp" android:background="#80F9F9F9" android:clickable="true" android:focusable="true" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>
作者:程序园中猿
链接:https://www.jianshu.com/p/db078107fa0c
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦