亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

安卓實現局部界面遮罩效果

標簽:
Android

背景

列表展示数据时,有些数据因为失效了,需要灰化展示。但是因为每一行数据里面包含多个view(如包含用户姓名、性别等等信息),不方便对每个view进行灰化设置,所以需要一个遮罩层将整行遮盖来达到灰化效果。大致效果如下:


webp

解决方案

列表的item布局采用RelativeLayout或者ConstraintLayout,在layout中增加一个空的view(遮罩层),刚好能盖住其他view,默认设置为不可见。在adapter里根据数据的有效性设置是否打开这层遮罩层。

带遮罩的item布局文件样例如下:
其中maskLayer为遮罩层view,如下几点需要重点注意

  1. android:layout_height="30dp" 这个高度要设置为固定的值,必须刚好和view原本高度相同,不能设置为wrap_content或match_parent。所以此方案不适用于item的高度不固定的情况。

  2. android:background="#80F9F9F9" 设置遮罩层的颜色,前两位是透明度(00到FF,值越小越透明。)

  3. 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 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消