• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    Java
  • License
    GNU Lesser Genera...
  • Created about 6 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

揭示效果布局,可以指定2个子布局,以圆形揭示效果切换选中状态

求职

RevealLayout

揭示效果布局,可以指定2个子布局,以圆形揭示效果切换选中状态

GitHub主页

Demo下载

截图

集成方式

添加依赖

  1. 在项目根目录的build.gradle添加仓库地址
allprojects {
	repositories {
		...
		maven { url 'https://www.jitpack.io' }
	}
}
  1. 在项目app目录的build.gradle添加依赖

从1.1.1版本开始,版本号前不加v,引用时需要注意。

dependencies {
	implementation 'com.github.goweii:RevealLayout:1.1.1'
}

布局文件引用

<per.goweii.reveallayout.RevealLayout
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_margin="5dp"
	app:rl_allow_revert="true"
	app:rl_anim_duration="1000"
	app:rl_check_with_expand="true"
	app:rl_checked="false"
	app:rl_checked_layout="@layout/reveal_layout_follow_checked"
	app:rl_uncheck_with_expand="true"
	app:rl_unchecked_layout="@layout/reveal_layout_follow_unchecked" />

代码中设置监听

revealLayout.setOnCheckedChangeListener(new RevealLayout.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RevealLayout revealLayout, boolean isChecked) {
        // TODO 
    }
});

自定义子类

如一个关注取消关注控件FollowView,只需要继承RevealLayout,然后复写以下3个方法:

  1. initAttr(AttributeSet attrs):获取子类的自定义属性
  2. createCheckedView():创建选中状态视图,并初始化自定义属性
  3. createUncheckedView():创建非选中状态视图,并初始化自定义属性
public class FollowView extends RevealLayout{
    private float mTvTextSize;
    private int mTvPaddingVertical = 0;
    private int mTvPaddingHorizontal = 0;
    private String mTvUnFollowText = "";
    private int mTvUnFollowBgColor;
    private int mTvUnFollowBgRes;
    private int mTvUnFollowTextColor;
    private String mTvFollowText = "";
    private int mTvFollowBgColor;
    private int mTvFollowBgRes;
    private int mTvFollowTextColor;

    public FollowView(Context context) {
        this(context, null);
    }

    public FollowView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FollowView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initAttr(AttributeSet attrs) {
        super.initAttr(attrs);
        DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
        TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.FollowView);
        mTvPaddingVertical = (int) array.getDimension(R.styleable.FollowView_fv_tv_padding_vertical, 0F);
        mTvPaddingHorizontal = (int) array.getDimension(R.styleable.FollowView_fv_tv_padding_horizontal, 0F);
        mTvTextSize = array.getDimension(R.styleable.FollowView_fv_text_size, metrics.scaledDensity * 14) / metrics.scaledDensity;
        mTvUnFollowText = array.getString(R.styleable.FollowView_fv_unfollowed_text);
        mTvUnFollowBgRes = array.getResourceId(R.styleable.FollowView_fv_unfollowed_bg_res, 0);
        mTvUnFollowBgColor = array.getColor(R.styleable.FollowView_fv_unfollowed_bg_color, 0);
        mTvUnFollowTextColor = array.getColor(R.styleable.FollowView_fv_unfollowed_text_color, 0);
        mTvFollowText = array.getString(R.styleable.FollowView_fv_followed_text);
        mTvFollowBgRes = array.getResourceId(R.styleable.FollowView_fv_followed_bg_res, 0);
        mTvFollowBgColor = array.getColor(R.styleable.FollowView_fv_followed_bg_color, 0);
        mTvFollowTextColor = array.getColor(R.styleable.FollowView_fv_followed_text_color, 0);
        array.recycle();
    }

    @Override
    protected View createCheckedView() {
        TextView tvFollow = new TextView(getContext());
        tvFollow.setTextSize(mTvTextSize);
        tvFollow.setText(mTvFollowText);
        tvFollow.setGravity(Gravity.CENTER);
        tvFollow.setSingleLine();
        if (mTvFollowBgRes > 0) {
            tvFollow.setBackgroundResource(mTvFollowBgRes);
        } else {
            tvFollow.setBackgroundColor(mTvFollowBgColor);
        }
        tvFollow.setTextColor(mTvFollowTextColor);
        tvFollow.setPadding(mTvPaddingHorizontal, mTvPaddingVertical, mTvPaddingHorizontal, mTvPaddingVertical);
        return tvFollow;
    }

    @Override
    protected View createUncheckedView() {
        TextView tvUnFollow = new TextView(getContext());
        tvUnFollow.setTextSize(mTvTextSize);
        tvUnFollow.setText(mTvUnFollowText);
        tvUnFollow.setGravity(Gravity.CENTER);
        tvUnFollow.setSingleLine();
        if (mTvUnFollowBgRes > 0) {
            tvUnFollow.setBackgroundResource(mTvUnFollowBgRes);
        } else {
            tvUnFollow.setBackgroundColor(mTvUnFollowBgColor);
        }
        tvUnFollow.setTextColor(mTvUnFollowTextColor);
        tvUnFollow.setPadding(mTvPaddingHorizontal, mTvPaddingVertical, mTvPaddingHorizontal, mTvPaddingVertical);
        return tvUnFollow;
    }
}

More Repositories

1

AnyLayer

Android稳定高效的浮层创建管理框架
Java
990
star
2

WanAndroid

最美WanAndroid客户端
Java
940
star
3

ActionBarEx

高拓展高自定义性ActionBar,完美替代Android系统默认
Java
266
star
4

Layer

Android浮层管理框架
Java
143
star
5

RxHttp

对RxJava2+Retrofit2+OkHttp3的封装
Java
68
star
6

AnyPermission

Android权限申请(运行时权限、未知应用安装权限、悬浮窗权限、显示通知和访问通知权限)
Java
52
star
7

SwipeBack

Android Activity滑动返回。支持4个方向,支持下层Activity联动和自定义动效。
Java
48
star
8

SwipeDragTreeRecyclerView

可滑动和拖拽的树形结构RecyclerView
Java
31
star
9

StatusBarCompat

国产Android系统状态栏暗亮色适配,支持自动根据背景色切换暗亮色模式
Java
30
star
10

LazyFragment

懒加载Fragment,提供可见和隐藏的回调,支持在ViewPager中多重嵌套,支持support和androidx
Java
28
star
11

VisualEffect

Used to achieve visual effects in Android, such as Gaussian blur, mosaic, watermark, etc.
Kotlin
27
star
12

AnyDialog

简化dialog创建,支持滑动关闭,支持嵌套滑动
Kotlin
25
star
13

Blurred

Android高斯模糊库,调教参数后可实现实时高斯模糊(<16ms,可达2~3ms)
Java
22
star
14

CropImageView

可自由指定自适应裁剪对齐点的ImageView
Java
19
star
15

CodeX

Android一维码二维码等生成解析和扫描,具有高扩展性和自定义性
Java
17
star
16

ShadowLayout

Android阴影布局,支持自定义边界形状
Java
12
star
17

PercentImageView

自由指定宽高比的ImageView
Java
7
star
18

KeyboardCompat

Android软键盘兼容库,支持开启关闭监听和EditText获取焦点时布局上移
Java
7
star
19

AnyView

快速将一个布局封装成一个自定义View
Java
5
star
20

ParallaxStackLayout

3D视差效果堆叠布局
Kotlin
4
star
21

FloatingLayer

替代Android自带的Dialog弹窗
Java
3
star
22

BaseStateAdapter

轻量级RecyclerView.Adapter封装,支持空布局,加载布局和多类型布局,一行代码添加点击事件
Java
3
star
23

AnyWindow

Java
3
star
24

MyCalc

Java
2
star
25

TestUrl

一些测试链接,包括在线音视频、下载等
2
star
26

NineGridLayout

九宫格布局,可自定义item的布局
Java
2
star
27

TableStringBuilder

Console table generator
Java
1
star
28

HeartView

Kotlin
1
star
29

maven-repository

1
star
30

Anole

Kotlin
1
star
31

Ponyo-Public

Android Debug Tools
1
star
32

names_launcher

Dart
1
star
33

goweii

1
star