SuperTextView 强大的textView

来源:互联网 发布:运动鞋清洗剂知乎 编辑:程序博客网 时间:2024/05/22 10:40

项目地址:

https://github.com/lygttpod/SuperTextView

SuperTextView

 API Android Arsenal  

重磅推出SuperTextView2.x版本,属性参数相比1.x有些变化,1.x的用户升级2.x的时候请注意

1、功能描述

SuperTextView是一个功能强大的View,可以满足日常大部分布局样式,开发者可已自行组合属性配置出属于自己风格的样式!可能描述起来没有概念,还是直接看效果图吧!

SuperButton拥有shape文件的大部分属性,从此写shape属性变得非常简单

CommonTextView只是SuperTextView的逻辑简化,其实功能并不差少哦,有兴趣的可以看看

如果觉得对你有用的话,点一下右上的星星赞一下吧!

2、 效果 Demo下载地址

3、如何使用

3.1、Android Studio导入方法,添加Gradle依赖

   先在项目根目录的 build.gradle 的 repositories 添加:

     allprojects {         repositories {            ...            maven { url "https://jitpack.io" }        }    }

然后在dependencies添加:

        dependencies {        ...        compile 'com.github.lygttpod:SuperTextView:2.1.3'        }

重写SuperTextView,功能更加全面,部分方法及属性有变更,1.x版本的老用户请注意

3.2、项目中如何使用

3.2.1、布局中如何使用(示例中只列出部分属性,开发者可根据具体需求使用其他属性)

            <com.allen.library.SuperTextView                android:layout_width="match_parent"                android:layout_height="80dp"                stv:sCenterBottomTextColor="@color/colorAccent"                stv:sCenterBottomTextString="限额说明>>"                stv:sCenterTopTextString=" "                stv:sCenterViewGravity="left_center"                stv:sLeftBottomTextString="招商银行(8888)"                stv:sLeftIconRes="@drawable/bank_zhao_shang"                stv:sLeftTopTextString="银行卡支付"                stv:sLeftViewGravity="left_center"                stv:sRightCheckBoxRes="@drawable/circular_check_bg"                stv:sRightViewType="checkbox" />        注意:                1、上下的线可以通过   sDividerLineType 设置  有四种显示方式 none,top,bottom,both                2、通过设置 sUseRipple=true 开启水波效果

3.2.2、代码中如何使用

       /**     * 可以通过链式设置大部分常用的属性值     */   superTextView.setLeftTopString("")                .setLeftString("")                .setLeftBottomString("")                .setCenterTopString("")                .setCenterString("")                .setCenterBottomString("")                .setRightTopString("")                .setRightString("")                .setRightBottomString("")                .setLeftIcon(0)                .setRightIcon(0)                .setCbChecked(true)                .setCbBackground(null)                .setLeftTvDrawableLeft(null)                .setLeftTvDrawableRight(null)                .setCenterTvDrawableLeft(null)                .setCenterTvDrawableRight(null)                .setRightTvDrawableLeft(null)                .setRightTvDrawableRight(null);                   superTextView.setShapeCornersRadius(20)                .setShapeCornersTopLeftRadius(20)                .setShapeCornersBottomLeftRadius(20)                .setShapeCornersTopRightRadius(20)                .setShapeCornersBottomRightRadius(20)                .setShapeStrokeColor(getResources().getColor(R.color.colorPrimary))                .setShapeStrokeWidth(1)                .setShapeSrokeDashWidth(1)                .setShapeStrokeDashGap(5)                .setShapeSolidColor(getResources().getColor(R.color.white))                .setShapeSelectorNormalColor(getResources().getColor(R.color.red_btn))                .setShapeSelectorPressedColor(getResources().getColor(R.color.gray))                .useShape();//设置完各个参数之后这句调用才生效

3.2.3点击事件(可根据需求选择实现单个或者多个点击事件)

        /**         * 根据实际需求对需要的View设置点击事件         */        /**         * 根据实际需求对需要的View设置点击事件         */        superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() {            @Override            public void onClickListener(SuperTextView superTextView) {                string = "整个item的点击事件";                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setLeftTopTvClickListener(new SuperTextView.OnLeftTopTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getLeftTopString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setLeftTvClickListener(new SuperTextView.OnLeftTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getLeftString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setLeftBottomTvClickListener(new SuperTextView.OnLeftBottomTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getLeftBottomString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setCenterTopTvClickListener(new SuperTextView.OnCenterTopTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getCenterTopString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setCenterTvClickListener(new SuperTextView.OnCenterTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getCenterString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setCenterBottomTvClickListener(new SuperTextView.OnCenterBottomTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getCenterBottomString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setRightTopTvClickListener(new SuperTextView.OnRightTopTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getRightTopString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setRightTvClickListener(new SuperTextView.OnRightTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getRightString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setRightBottomTvClickListener(new SuperTextView.OnRightBottomTvClickListener() {            @Override            public void onClickListener() {                string = superTextView.getRightBottomString();                Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();            }        }).setLeftImageViewClickListener(new SuperTextView.OnLeftImageViewClickListener() {            @Override            public void onClickListener(ImageView imageView) {                Toast.makeText(ClickActivity.this, "左边图片", Toast.LENGTH_SHORT).show();            }        }).setRightImageViewClickListener(new SuperTextView.OnRightImageViewClickListener() {            @Override            public void onClickListener(ImageView imageView) {                Toast.makeText(ClickActivity.this, "右边图片", Toast.LENGTH_SHORT).show();            }        });        superTextView_cb.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() {            @Override            public void onClickListener(SuperTextView superTextView) {                superTextView.setCbChecked(!superTextView.getCbisChecked());            }        }).setCheckBoxCheckedChangeListener(new SuperTextView.OnCheckBoxCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                Toast.makeText(ClickActivity.this, "" + isChecked, Toast.LENGTH_SHORT).show();            }        });        superTextView_switch.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() {            @Override            public void onClickListener(SuperTextView superTextView) {                superTextView.setSwitchIsChecked(!superTextView.getSwitchIsChecked());            }        }).setSwitchCheckedChangeListener(new SuperTextView.OnSwitchCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                Toast.makeText(ClickActivity.this, "" + isChecked, Toast.LENGTH_SHORT).show();            }        });

3.2.4使用第三方库(Picasso或者Glide)加载网络图片

        String url1 = "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG";        String url2 = "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=219781665,3032880226&fm=80&w=179&h=119&img.JPEG";        String url3 = "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG";                Picasso.with(this)                .load(url1)                .placeholder(R.drawable.head_default)                .into(superTextView.getLeftIconIV());        Glide.with(this)                .load(url2)                .placeholder(R.drawable.head_default)                .fitCenter()                .into(superTextView2.getRightIconIV());        Glide.with(this)                .load(url3)                .placeholder(R.drawable.head_default)                .into(new SimpleTarget<GlideDrawable>() {                    @Override                    public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {                        superTextView3.setRightTvDrawableRight(resource);                    }                });

3.2.5、属性说明(以下属性全部可以通过xml文件配置和代码进行设置)

属性名字段描述默认值sLeftTextStringstring左边文字字符串 sLeftTopTextStringstring左上文字字符串 sLeftBottomTextStringstring左下文字字符串 sCenterTextStringstring中间文字字符串 sCenterTopTextStringstring中上文字字符串 sCenterBottomTextStringstring中下文字字符串 sRightTextStringstring右边文字字符串 sRightTopTextStringstring右上文字字符串 sRightBottomTextStringstring右下文字字符串 sLeftTextColorcolor左边文字颜色默认0xFF373737sLeftTopTextColorcolor左上文字颜色默认0xFF373737sLeftBottomTextColorcolor左下文字颜色默认0xFF373737sCenterTextColorcolor中间文字颜色默认0xFF373737sCenterTopTextColorcolor中上文字颜色默认0xFF373737sCenterBottomTextColorcolor中下文字颜色默认0xFF373737sRightTextColorcolor左边文字颜色默认0xFF373737sRightTopTextColorcolor右上文字颜色默认0xFF373737sRightBottomTextColorcolor右下文字颜色默认0xFF373737sLeftTextSizedimension左边字体大小默认15spsLeftTopTextSizedimension左上字体大小默认15spsLeftBottomTextSizedimension左下字体大小默认15spsCenterTextSizedimension中间字体大小默认15spsCenterTopTextSizedimension中上字体大小默认15spsCenterBottomTextSizedimension中下字体大小默认15spsRightTextSizedimension右边字体大小默认15spsRightTopTextSizedimension右上字体大小默认15spsRightBottomTextSizedimension右下字体大小默认15spsLeftLinesinteger左边文字显示行数默认1sLeftTopLinesinteger左上文字显示行数默认1sLeftBottomLinesinteger左下文字显示行数默认1sCenterLinesinteger中间文字显示行数默认1sCenterTopLinesinteger中上文字显示行数默认1sCenterBottomLinesinteger中下文字显示行数默认1sRightLinesinteger右边文字显示行数默认1sRightTopLinesinteger右上文字显示行数默认1sRightBottomLinesinteger右下文字显示行数默认1sLeftMaxEmsinteger左边文字显示个数默认15sLeftTopMaxEmsinteger左上文字显示个数默认15sLeftBottomMaxEmsinteger左下文字显示个数默认15sCenterMaxEmsinteger中间文字显示个数默认15sCenterTopMaxEmsinteger中上文字显示个数默认15sCenterBottomMaxEmsinteger中下文字显示个数默认15sRightMaxEmsinteger右边文字显示个数默认15sRightTopMaxEmsinteger右上文字显示个数默认15sRightBottomMaxEmsinteger右下文字显示个数默认15sLeftViewGravityenum左边文字对齐方式
left_center(左对齐)
center(居中)
right_center(右对齐)默认centersCenterViewGravityenum中间文字对齐方式
left_center(左对齐)
center(居中)
right_center(右对齐)默认centersRightViewGravityenum右边文字对齐方式
left_center(左对齐)
center(居中)
right_center(右对齐)默认centersLeftTvDrawableLeftreference左边TextView左侧的drawable sLeftTvDrawableRightreference左边TextView右侧的drawable sCenterTvDrawableLeftreference中间TextView左侧的drawable sCenterTvDrawableRightreference中间TextView右侧的drawable sRightTvDrawableLeftreference右边TextView左侧的drawable sRightTvDrawableRightreference右边TextView右侧的drawable sLeftTvDrawableWidthdimension左边TextView的drawable的宽度 sLeftTvDrawableHeightdimension左边TextView的drawable的高度 sCenterTvDrawableWidthdimension中间TextView的drawable的宽度 sCenterTvDrawableHeightdimension中间TextView的drawable的高度 sRightTvDrawableWidthdimension右边TextView的drawable的宽度 sRightTvDrawableHeightdimension右边TextView的drawable的高度 sTextViewDrawablePaddingdimensionTextView的drawable对应的Padding默认10dpsLeftViewWidthdimension左边textView的宽度 为了中间文字左对齐的时候使用 sTopDividerLineMarginLRdimension上边分割线的MarginLeft和MarginRight默认0dpsTopDividerLineMarginLeftdimension上边分割线的MarginLeft默认0dpsTopDividerLineMarginRightdimension上边分割线的MarginRight默认0dpsBottomDividerLineMarginLRdimension下边分割线的MarginLeft和MarginRigh默认0dpsBottomDividerLineMarginLeftdimension下边分割线的MarginLeft默认0dpsBottomDividerLineMarginRightdimension下边分割线的MarginRight默认0dpsDividerLineColorcolor分割线的颜色默认0xFFE8E8E8sDividerLineHeightdimension分割线的高度默认0.5dpsDividerLineTypeenum分割线显示方式 
none(不显示分割线)
top(显示上边的分割线)
bottom(显示下边的分割线)
both(显示上下两条分割线)默认bottomsLeftViewMarginLeftdimension左边view的MarginLeft默认10dpsLeftViewMarginRightdimension左边view的MarginRight默认10dpsCenterViewMarginLeftdimension中间view的MarginLeft默认10dpsCenterViewMarginRightdimension中间view的MarginRight默认10dpsRightViewMarginLeftdimension右边view的MarginLeft默认10dpsRightViewMarginRightdimension右边view的MarginRight默认10dpsLeftTextIsBoldboolean左边文字是否加粗默认falsesLeftTopTextIsBoldboolean左上文字是否加粗默认falsesLeftBottomTextIsBoldboolean左下文字是否加粗默认falsesCenterTextIsBoldboolean中间文字是否加粗默认falsesCenterTopTextIsBoldboolean中上文字是否加粗默认falsesCenterBottomTextIsBoldboolean中下文字是否加粗默认falsesRightTextIsBoldboolean右边文字是否加粗默认falsesRightTopTextIsBoldboolean右上文字是否加粗默认falsesRightBottomTextIsBoldboolean右下文字是否加粗默认falsesLeftIconResreference左边图片资源 可以用来显示网络图片或者本地 sRightIconResreference右边图片资源 可以用来显示网络图片或者本地 sLeftIconWidthdimension左边图片资源的宽度 用于固定图片大小的时候使用 sLeftIconHeightdimension左边图片资源的高度 用于固定图片大小的时候使用 sRightIconWidthdimension右边图片资源的宽度 用于固定图片大小的时候使用 sRightIconHeightdimension右边图片资源的高度 用于固定图片大小的时候使用 sLeftIconMarginLeftdimension左边图片资源的MarginLeft默认10dpsRightIconMarginRightdimension右边图片资源的MarginLeft默认10dpsCenterSpaceHeightdimension上中下三行文字的间距默认5dpsRightCheckBoxResreference右边CheckBox的资源 sRightCheckBoxMarginRightdimension右边CheckBox的MarginRight默认10dpsIsCheckedboolean右边CheckBox是否选中默认 falsesUseRippleboolean是否开启点击出现水波效果默认 truesBackgroundDrawableResreferenceSuperTextView的背景资源 sRightViewTypeenum右边显示的特殊View
checkbox
switchBtn默认都不显示sRightSwitchMarginRightdimension右边SwitchBtn的MarginRight默认10dpsSwitchIsCheckedboolean右边SwitchBtn是否选中默认 falsesTextOffstringTextOff默认""sTextOnstringTextOn默认""sSwitchMinWidthdimensionSwitchMinWidth系统默认sSwitchPaddingdimensionSwitchPadding系统默认sThumbTextPaddingdimensionThumbTextPadding系统默认sThumbResourcereference右边SwitchBtn自定义选中资源系统默认sTrackResourcereference右边SwitchBtn自定义未选中资源系统默认sUseShapeboolean是否使用shape设置圆角及触摸反馈
设为true之后才能使用一下属性默认falsesShapeSolidColorcolor填充色默认falsesShapeSelectorPressedColorcolor按下时候的颜色默认0xffffffffsShapeSelectorNormalColorcolor正常显示的颜色默认0xffffffffsShapeCornersRadiusdimension四个角的圆角半径默认0dpsShapeCornersTopLeftRadiusdimension左上角的圆角半径默认0dpsShapeCornersTopRightRadiusdimension右上角的圆角半径默认0dpsShapeCornersBottomLeftRadiusdimension左下角的圆角半径默认0dpsShapeCornersBottomRightRadiusdimension右下角的圆角半径默认0dpsShapeStrokeWidthdimension边框宽度默认0dpsShapeStrokeDashWidthdimension虚线宽度默认0dpsShapeStrokeDashGapdimension虚线间隙宽度默认0dpsShapeStrokeColorcolor边框颜色默认0dpsLeftTextBackgroundreference左边textView的背景 sCenterTextBackgroundreference中间textView的背景 sRightTextBackgroundreference右边textView的背景 

黑格尔曾说过:存在即合理。SuperTextView的出现应该就是某种需求下的产物。

原创粉丝点击