Code Monkey home page Code Monkey logo

androids's Introduction

Androids

Androids是本人根据平时的项目实践经验,为了提高Android开发效率而写的一个工具SDK;里面提供了一些工具类以及自定义View,可在实际项目开发时直接使用。

ANDROIDS

使用

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

dependencies {
    compile 'com.github.1993hzw:Androids:1.2.4'
}

项目结构

--AndroidsDemo 使用例子

--androids 库工程

自定义View

  • STextView/SLayout

可直接在布局文件设置shape和selector,实现点击效果

点击查看示例代码

STextView支持的属性

<attr name="stv_text_color_selected" format="color"/>
<attr name="stv_text_color_pressed" format="color"/>
<attr name="stv_text_color_disable" format="color"/>

STextView/SLayout支持的属性

<!-- 背景状态 -->
<attr name="sel_background_pressed" format="reference|color"/>
<attr name="sel_background_selected" format="reference|color"/>

<!-- 背景形状 -->
<attr name="sel_background_shape" format="enum">
    <enum name="rect" value="0"/>
    <enum name="oval" value="1"/>
    <enum name="line" value="2"/>
    <enum name="ring" value="3"/>
</attr>
<!-- 背景圆角 -->
<attr name="sel_background_corners" format="dimension"/>
<attr name="sel_background_corner_topLeft" format="dimension"/>
<attr name="sel_background_corner_topRight" format="dimension"/>
<attr name="sel_background_corner_bottomLeft" format="dimension"/>
<attr name="sel_background_corner_bottomRight" format="dimension"/>

<!-- 背景边框默认状态 -->
<attr name="sel_background_border_color" format="color"/>
<attr name="sel_background_border_width" format="dimension"/>
<!-- 背景边框状态 -->
<attr name="sel_background_border_pressed" format="color"/>
<attr name="sel_background_border_selected" format="color"/>

<!-- ripple水波纹效果-->
<attr name="sel_background_ripple" format="reference|color"/>
<attr name="sel_background_ripple_mask" format="reference|color"/>
<!-- ripple mask形状(仅在sel_background_ripple_mask为color时生效)-->
<attr name="sel_background_ripple_mask_shape" format="enum">
    <enum name="rect" value="0"/>
    <enum name="oval" value="1"/>
    <enum name="line" value="2"/>
    <enum name="ring" value="3"/>
</attr>
<!-- ripple mask圆角 -->
<attr name="sel_background_ripple_mask_corners" format="dimension"/>
<attr name="sel_background_ripple_mask_corner_topLeft" format="dimension"/>
<attr name="sel_background_ripple_mask_corner_topRight" format="dimension"/>
<attr name="sel_background_ripple_mask_corner_bottomLeft" format="dimension"/>
<attr name="sel_background_ripple_mask_corner_bottomRight" format="dimension"/>
  • ShapeImageView

可设置形状(圆形、圆角矩形)的ImageView

点击查看示例代码

<attr name="siv_shape" format="enum">
    <enum name="rect" value="1"/>
    <enum name="circle" value="2"/>
    <enum name="oval" value="3"/>
</attr>
<attr name="siv_round_radius" format="dimension"/>
<attr name="siv_round_radius_leftTop" format="dimension"/>
<attr name="siv_round_radius_leftBottom" format="dimension"/>
<attr name="siv_round_radius_rightTop" format="dimension"/>
<attr name="siv_round_radius_rightBottom" format="dimension"/>
<attr name="siv_border_size" format="dimension"/>
<attr name="siv_border_color" format="color"/>

《Android自定义View——可设置形状(圆形、圆角矩形、椭圆)的ImageView,抗锯齿》

  • MaskImageView

可在背景图和前景图显示遮罩效果的ImageView

点击查看示例代码

<!-- 遮罩的层面:背景\前景图-->
<attr name="miv_mask_level" format="enum">
    <enum name="background" value="1"/>
    <enum name="foreground" value="2"/>
</attr>
<!-- 设置了setClickable(true)才生效,默认开启遮罩-->
<attr name="miv_is_show_mask_on_click" format="boolean"/>
<attr name="miv_mask_color" format="color"/>
<!--是否忽略图片的透明度,默认为true,透明部分不显示遮罩 -->
<attr name="miv_is_ignore_alpha" format="boolean"/>

《Android自定义View——可在背景图和前景图显示遮罩效果的ImageView》

  • RatioImageView

可以设置宽高比例的ImageView

点击查看示例代码

<!-- 宽度是否根据src图片的比例来测量(高度已知) -->
<attr name="riv_is_width_fix_drawable_size_ratio" format="boolean"/>
<!-- 高度是否根据src图片的比例来测量(宽度已知) -->
<attr name="riv_is_height_fix_drawable_size_ratio" format="boolean"/>
<!--当mIsWidthFitDrawableSizeRatio生效时,最大宽度-->
<attr name="riv_max_width_when_width_fix_drawable" format="dimension"/>
<!--当mIsHeightFitDrawableSizeRatio生效时-->
<attr name="riv_max_height_when_height_fix_drawable" format="dimension"/>
<!-- 高度设置,参考宽度,如0.5 , 表示 高度=宽度×0.5 -->
<attr name="riv_height_to_width_ratio" format="float"/>
<!-- 宽度设置,参考高度,如0.5 , 表示 宽度=高度×0.5 -->
<attr name="riv_width_to_height_ratio" format="float"/>
<!--宽度和高度,避免layout_width/layout_height会在超过屏幕尺寸时特殊处理的情况-->
<attr name="riv_width" format="dimension"/>
<attr name="riv_height" format="dimension"/>

《Android自定View——可以设置宽高比例的ImageView》

  • ScrollPickerView

滚动选择器,支持循环滚动,可实现生日选择器,老虎机等

   <!--滚动选择器通用属性-->
    <declare-styleable name="ScrollPickerView">
        <!-- 中间item的背景-->
        <attr name="spv_center_item_background" format="reference|color"/>
        <!-- 可见的item数量,默认为3个-->
        <attr name="spv_visible_item_count" format="integer"/>
        <!-- 中间item的位置,默认为 mVisibleItemCount / 2-->
        <attr name="spv_center_item_position" format="integer"/>
        <!-- 是否循环滚动,默认为true,开启-->
        <attr name="spv_is_circulation" format="boolean"/>
        <!-- 不允许父组件拦截触摸事件,设置为true为不允许拦截,此时该设置才生效 -->
        <attr name="spv_disallow_intercept_touch" format="boolean"/>
        <!-- 滚动的方向-->
        <attr name="spv_orientation" format="string">
            <enum name="horizontal" value="1"/>
            <enum name="vertical" value="2"/>
        </attr>
    </declare-styleable>
    
    <!--文字选择器-->
    <declare-styleable name="StringScrollPicker">
        <!--文字渐变大小-->
        <attr name="spv_min_text_size" format="dimension"/>
        <attr name="spv_max_text_size" format="dimension"/>
        <!--文字渐变颜色-->
        <attr name="spv_start_color" format="color"/>
        <attr name="spv_end_color" format="color"/>
        <!--文字最大行宽-->
        <attr name="spv_max_line_width" format="dimension"/>
        <!--文字对齐方式-->
        <attr name="spv_alignment" format="enum">
            <enum name="center" value="1"/>
            <enum name="left" value="2"/>
            <enum name="right" value="3"/>
        </attr>
    </declare-styleable>

    <!--图片选择器-->
    <declare-styleable name="BitmapScrollPicker">
        <!-- 绘制图片的方式-->
        <attr name="spv_draw_bitmap_mode" format="string">
            <enum name="fill" value="1"/>
            <enum name="center" value="2"/>
            <enum name="size" value="3"/>
        </attr>
        <!-- 绘制图片的方式为size时,指定的图片绘制大小-->
        <attr name="spv_draw_bitmap_width" format="dimension"/>
        <attr name="spv_draw_bitmap_height" format="dimension"/>
        <!-- item内容缩放倍数-->
        <attr name="spv_min_scale" format="float"/>
        <attr name="spv_max_scale" format="float"/>
    </declare-styleable>

点击查看示例代码

《 Android自定义view——滚动选择器》

《 android图片滚动选择器的实现》

《 Android滚动选择器——水平滚动》

  • KeyboardLayout

监听输入法键盘的弹起与隐藏,可实现输入法和工具栏无缝切换

点击查看示例代码

《Android监听输入法并获取高度——输入法与页面布局无缝切换》

  • DragListView

可拖拽的ListView,拖拽排序

点击查看示例代码

《Android自定义View——可拖拽的ListView》

  • EasyAdapter

用于RecyclerView的适配器,可支持设置点击、单选和多选模式

点击查看示例代码

Kotlin版实现

工具类

  • 图片加载器

点击查看示例代码

更新

  • v1.2.4(18)

1.增加工具类EllipsizeUtils,支持多行和根据关键字省略

  • v1.2.3(17)

1.fix:SelectorAttrs在低版本上没有设置背景色时显示黑色

  • v1.2.2(16)

1.优化手势识别类TouchGestureDetector,ScaleGestureDetector使用Api27源码

  • v1.2(14)

1.新增EasyAdapter,用于RecyclerView的适配器,可支持设置点击、单选和多选模式。(Kotlin版实现

2.修复SLayout没有设置背景色时导致border异常的问题

  • v1.1.8.1(13)

1.修复某些情况下滚动选择器不回调监听器的问题

  • v1.1.8(12)

1.SLayout支持水波纹效果

2.兼容旧版本的sel_background属性

  • v1.1.7.1(11)

1.修复SelectorAttrs中background_border的bug。

  • v1.1.7(10)

1.完善SelectorAttrs逻辑,支持设置图片。

2.增加TouchGestureDetector

  • v1.1.6(9)

文字滚动选择器支持文字换行.

androids's People

Contributors

1993hzw avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.